Ensure_List_ContentType_Order

Language:
PowerShell
Keywords:
SharePoint
Code Snippet

## Ensure_s the order of a Content Type within an SPList.. if it does, do nothing; if it does not, move it
Function Ensure_List_ContentType_Order( [Microsoft.SharePoint.SPList]$tList
                                      , [System.String]$ctName
                                      , [System.Int16]$tOrder
                                      ) {
    if ($tList.RootFolder.ContentTypeOrder[$tOrder - 1].Name -ne $ctName) {
        $ctOrder = $tList.RootFolder.ContentTypeOrder
        $ctExisting = $ctOrder | where { $_.Name -eq $ctName }                   # need to identify this way to ensure that Remove will match instances
        $ctOrder.Remove($ctExisting) | Out-Null
        $ctOrder.Insert($tOrder - 1, $tList.ContentTypes[$ctName])
        Write-Output([System.String]::Format("List [{0}] : Moving Content Type [{1}] to location [{2}]", $tList.Title, $ctName, $tOrder))
        $tList.RootFolder.UniqueContentTypeOrder = $ctOrder
        #$tList.Update()
    }
} # Function Ensure_List_ContentType_Order(...)


Created 2011-10-13
comments powered by Disqus
Login