I’ve previously posted PowerShell scripts that allow you to extract Content Types or Fields from a SharePoint site. But last week a commenter by the named Jeff posed a valid question. What if I want to extract all Content Types in a SharePoint site, and show the associated Fields for each of them?
While my previous scripts does not allow for that, it wasn’t all that hard to combine the two scripts into one. Over the weekend I quickly threw something together and the result is a PowerShell script that iterates through each Content Type and prints out each Field it finds. It’s pretty simple. I’ve posted the script below, and I’ll also post a truncated version of the output for 2007 and 2010 in later blog posts.
# Output all available Content Type GUIDs and their respective fields
#
# Syntax
# ./listCtFields
#
# Parameters
# none
#
# Settings
# Only change the -value parameter!
#
set-variable -option constant -name url -value "http://localhost" # Site collection
set-variable -option constant -name out -value "ContentTypes.csv" # Site collection
# End of settings
$site = new-object Microsoft.SharePoint.SPSite($url)
$cts = $site.rootweb.ContentTypes
echo "Processing…"
‘"CT Name"’ + `
‘,"CT ID"’ + `
‘,"CT Description"’ + `
‘,"CT Group"’ +
‘,"Field Title"’ + `
‘,"Field Internal Name"’ + `
‘,"Field ID"’ + `
‘,"Field Group"’ + `
‘,"Field Max Length"’ + `
‘,"Field Description"’ | Out-File $out
ForEach ($id in $cts)
{
ForEach ($field in $id.Fields)
{
‘"’ + $id.Name + `
‘","’ + $id.Id + `
‘","’ + $id.Description + `
‘","’ + $id.Group + `
‘","’ + $field.Title + `
‘","’ + $field.InternalName + `
‘","’ + $field.Id + `
‘","’ + $field.Group + `
‘","’ + $field.MaxLength + `
‘","’ + $field.Description + `
‘"’ | Out-File $out -append
}
}
$site.Dispose()
echo "Finished!"
# Changelog
#
# v1.0 – February 28, 2011
# First release
Leave a Reply to Chris Cancel reply