Ensure_List_ContentType_Includes

Language:
PowerShell
Keywords:
SharePoint
Code Snippet

## Ensures that an SPContentType exists within an SPList.. if it does, do nothing; if it does not, add it
Function Ensure_List_ContentType_Includes( [Microsoft.SharePoint.SPList]$tList
                                         , [Microsoft.SharePoint.SPContentType]$tContentType
                                         ) {
    if ($tList.ContentTypes[$tContentType.Name] -eq $null) {
        $tList.ContentTypes.Add($tContentType) | Out-Null
        Write-Output([System.String]::Format("List [{0}] : Adding Content Type [{1}]", $tList.Title, $tContentType.Name))
        $tList.Update()
    }
} # Function Ensure_List_ContentType_Includes(...)


Created 2011-10-13
comments powered by Disqus
Login