Friday, October 9, 2015
Powershell script remove contenttypes from list
#Get site object and specify name of the library to look for in each site
$site = Get-SPSite http://URL
$lookForList = "ListName"
$ContentType = "CTName"
#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[$ContentType]
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()
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment