So you just found the wicked awesome list of content types and life is good, but you kinda wish you could get a hold of all those content types and column fields that you made yourself. No worries, Powershell is your trusted friend who’s always ready to help.
Below are two very basic Powershell scripts. They both connect to a specified site collection, and one exports Content Types while the other exports Column Fields.
These are the exact scripts I used previously and I just whipped them up in about 10 minutes so they’re not very fancy. Apparently there’s an export to csv function in Powershell, but I didn’t know that at the point so I just used the Output-File command.
You can spruce this up if you want, but this should give you the basic functionality to save them in a spreadsheet. The scripts returns ALL content types and column fields, so it’ll show both the default ones and the ones that you’ve created.
# Output all available Content Type GUIDs to ContentTypes.csv
#
# Syntax
# ./listCntTypID
#
# 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)
$web = $site.rootweb.ContentTypes
echo "Processing…"
ForEach ($id in $web)
{
‘"’ + $id.Name + `
‘","’ + $id.Id + `
‘","’ + $id.Description + `
‘","’ + $id.Group + `
‘","’ + $id.ParentList + `
‘"’ | Out-File $out -append
}
$site.Dispose()
echo "Finished!"
# Changelog
#
# v1.0 – August 25th, 2008
# First release
# Description
# Output all available Column Field GUIDs to ColumnFields.csv
#
# Syntax
# ./listColFldID
#
# 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 "ColumnFields.csv" # Output file
# End of settings
$site = new-object Microsoft.SharePoint.SPSite($url)
$web = $site.rootweb.Fields
echo "Processing..."
ForEach ($id in $web)
{
'"' + $id.Title + `
'","' + $id.Id + `
'","' + $id.InternalName + `
'","' + $id.MaxLength + `
'","' + $id.Description + `
'","' + $id.Group + `
'","' + $id.TypeShortDescription + `
'"' | Out-File $out -append
}
$site.Dispose()
echo "Finished!"
# Changelog
#
# v1.0 - August 25th, 2008
# First releaseIf you wish you can change the constants to point to the site collection of your choice. You can also specify an alternate name of the output file.
Leave a Reply