Aarebrot.net

Frode's website about Sharepoint and other stuff...

  • Increase font size
  • Default font size
  • Decrease font size

Powershell: Retrieve Content Types and Column Fields

E-mail Print
User Rating: / 0
PoorBest 

So you just downloaded 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 I've attached 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.

  1. # Description
  2. #   Output all available Content Type GUIDs to ContentTypes.csv
  3. #
  4. # Syntax
  5. #   ./listCntTypID
  6. #
  7. # Parameters
  8. #   none
  9. #
  10. # Settings
  11. #   Only change the -value parameter!
  12. #
  13. set-variable -option constant -name url     -value "http://localhost"       # Site collection
  14. set-variable -option constant -name out     -value "ContentTypes.csv"           # Site collection
  15. # End of settings
  16.  
  17. $site   =    new-object Microsoft.SharePoint.SPSite($url)
  18. $web    = $site.rootweb.ContentTypes
  19. echo "Processing..."
  20. ForEach ($id in $web)
  21. {
  22.     '"' + $id.Name + `
  23.     '","' + $id.Id + `
  24.     '","' + $id.Description + `
  25.     '","' + $id.Group + `
  26.     '","' + $id.ParentList + `
  27.     '"' | Out-File $out -append
  28. }
  29. $site.Dispose()
  30. echo "Finished!"
  31.  
  32. # Changelog
  33. #
  34. #   v1.0 - August 25th, 2008
  35. #       First release

  1. # Description
  2. #   Output all available Column Field GUIDs to ColumnFields.csv
  3. #
  4. # Syntax
  5. #   ./listColFldID
  6. #
  7. # Parameters
  8. #   none
  9. #
  10. # Settings
  11. #   Only change the -value parameter!
  12. #
  13. set-variable -option constant -name url     -value "http://localhost"       # Site collection
  14. set-variable -option constant -name out     -value "ColumnFields.csv"           # Output file
  15. # End of settings
  16.  
  17. $site   =    new-object Microsoft.SharePoint.SPSite($url)
  18. $web    = $site.rootweb.Fields
  19. echo "Processing..."
  20. ForEach ($id in $web)
  21. {
  22.     '"' + $id.Title + `
  23.     '","' + $id.Id + `
  24.     '","' + $id.InternalName + `
  25.     '","' + $id.MaxLength + `
  26.     '","' + $id.Description + `
  27.     '","' + $id.Group + `
  28.     '","' + $id.TypeShortDescription + `
  29.     '"' | Out-File $out -append
  30. }
  31. $site.Dispose()
  32. echo "Finished!"
  33.  
  34. # Changelog
  35. #
  36. #   v1.0 - August 25th, 2008
  37. #       First release

If 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.

Attachments:
 listColFldID.ps1[Powershell: List Column Fields in Site Collection]0 KbAug-25-2008 12:02pm
 listConTypID.ps1[Powershell: List Content Types in Site Collection]0 KbAug-25-2008 12:02pm
Last Updated ( Monday, 10 November 2008 09:15 )  

Add your comment

Your name:
Subject:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification: