Monday, January 16, 2012

Powershell script delete content type from document library in your Sharepoint 2010 site collection

#Get site object and specify name of the library to look for in each site
$site = Get-SPSite http://yoursite.com/
$lookForList = "Document”
$stringCTRemove = "Your Content type"
#Walk through each site and change content types on the list specified
$site | Get-SPWeb -Limit all | ForEach-Object {
   
    write-host "Checking site:"$_.Title
   
    #Check list exists
    $docLibrary = $_.Lists[$lookForList]
   
    #Remove unwanted content types from the list
    if($docLibrary -ne $null)
    {
        $ctToRemove = $docLibrary.ContentTypes[$stringCTRemove]
        write-host "Removing content type" $ctToRemove.Name "from list" $docLibrary.Title
        $docLibrary.ContentTypes.Delete($ctToRemove.Id)
        $docLibrary.Update()
    }
    else
    {
        write-host "The list" $lookForList "does not exist in site" $_.Title
    }
}
#Dispose of the site object
$site.Dispose()


No comments:

Post a Comment