
[SPS] Export Content Types and Site Columns using PowerShell
So, here goes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
#Get CTYPES and Site Columns ##Loading SPS Snapin if ($snapin -eq $null) { Write-Host "Loading SharePoint Powershell Snapin`r`n" Add-PSSnapin "Microsoft.SharePoint.Powershell" } ## Defining Variables $WEB_APPLICATION_URL = "http://2013.pbnet.pbnet.local" $CTS_FILE_PATH = "C:\temp\CTYPE\2013_TeamSite_ContentTypes.csv" $FIELDS_FILE_PATH = "C:\temp\CTYPE\2013_TeamSite_Fields.csv" $CT_FIELDS_FILE_PATH = "C:\temp\CTYPE\2013_TeamSite_CTs_And_Fields.csv" ## Initialization echo "Initializing variables" '"CT Name","CT Description","CT ID","CT Group","CT Parent ID"' | Out-File $CTS_FILE_PATH; '"Field Title","Field Description","Field Internal Name","Field ID","Field Group","Field Type"' | Out-File $FIELDS_FILE_PATH; '"CT Name","Field Title","CT ID","Field ID"' | Out-File $CT_FIELDS_FILE_PATH; $AllContentTypes = @(); $AllFields = @(); ## Get WebApp and Cycle through echo "Entering web application $WEB_APPLICATION_URL" $webApplication = Get-SPWebApplication -identity $WEB_APPLICATION_URL ForEach ($siteCollection in $webApplication.Sites) { ForEach($subSite in $siteCollection.AllWebs) { $subsiteUrl = $subsite.Url; echo "Extracting info from $subSiteUrl"; $contentTypes = $subSite.ContentTypes; ForEach ($contentType in $contentTypes) { If (!$AllContentTypes.Contains($contentType.Id)) { $AllContentTypes += $contentType.Id; # writing Content types CSV '"' + $contentType.Name + '","' + $contentType.Description + '","' + $contentType.Id + '","' + $contentType.Group + '","' + $contentType.Parent.Id + '"' | Out-File $CTS_FILE_PATH -Append ForEach ($field in $contentType.Fields) { If (!$AllFields.Contains($field.Id)) { $AllFields += $field.Id; # writing Fields CSV '"' + $field.Title + '","' + $field.Description + '","' + $field.Id + '","' + $field.Group + '","' + $field.Type + '","' | Out-File $FIELDS_FILE_PATH -Append; } '"' + $contentType.Name + '","' + $field.Title + '","' + $contentType.Id + '","' + $field.Id + '","' | Out-File $CT_FIELDS_FILE_PATH -Append; } } } } } echo "Script Completed!"; |