Ensure_List_ContentType_Excludes

Language:
PowerShell
Keywords:
SharePoint
Code Snippet

## Ensure_s that an SPContentType does NOT exists within an SPList.. if it does, do nothing; if it does not, remove it
Function Ensure_List_ContentType_Excludes( [Microsoft.SharePoint.SPList]$tList
                                         , $ctName
                                         ) {
    if ($tList.ContentTypes[$ctName] -ne $null) {
        $tList.ContentTypes.Delete($tList.ContentTypes[$ctName].Id) | Out-Null
        Write-Output([System.String]::Format("List [{0}] : Removing Content Type [{1}]", $tList.Title, $ctName))
        $tList.Update()
    }
} # Function Ensure_List_ContentType_Excludes(...)


Created 2011-10-13
comments powered by Disqus
Login