Powershell script to Restore the SharePoint Site Content Types From XML File

$destWeb = Get-SPWeb

#$xmlFilePath = “C:\Install\ScriptDocument.xml”


Function CreateCTypes($xmlFilePath)


#Create Site Content Types

$ctsXML = [xml](Get-Content($xmlFilePath))

$ctsXML.ContentTypes.ContentType | ForEach-Object {


#Create Content Type object inheriting from parent

$spContentType = New-Object Microsoft.SharePoint.SPContentType ($_.ID,$destWeb.ContentTypes,$_.Name)


#Set Content Type description and group

$spContentType.Description = $_.Description

$spContentType.Group = $_.Group


$_.Fields.Field | ForEach-Object {



#Create a field link for the Content Type by getting an existing column

$spFieldLink = New-Object Microsoft.SharePoint.SPFieldLink ($destWeb.Fields[$_.DisplayName])


#Check to see if column should be Optional, Required or Hidden

if ($_.Required -eq “TRUE”) {$spFieldLink.Required = $true}

if ($_.Hidden -eq “TRUE”) {$spFieldLink.Hidden = $true}


#Add column to Content Type





#Create Content Type on the site and update Content Type object

$ct = $destWeb.ContentTypes.Add($spContentType)


write-host “Content type” $ct.Name “has been created”






CreateCTypes “C:\Install\ScriptDocument.xml”

Leave a Reply

Your email address will not be published. Required fields are marked *