I have a URL for subsite mynews: for example: http://something.good/news/mynews I want to add custom content type 'NewsCT' to Pages library of this mynews subsite using powershell. How I do that?
1 Answer
Following PS script should help:
#Get site object and specify name of the library to look for in each site
$site = Get-SPSite http://something.good
$lookForList = "Pages"
#Walk through each site and change content types on the list specified
$siteA = $site.OpenWeb("http://something.good/news/mynews")
write-host "Checking site:" $siteA.Title
#Make sure content types are allowed on the list specified
$docLibrary = $siteA.Lists[$lookForList]
if ($docLibrary -ne $null)
{
$docLibrary.ContentTypesEnabled = $true
$docLibrary.Update()
#Add site content types to the list
$ctToAdd = $siteA.ContentTypes["NewsCT"]
$ct = $docLibrary.ContentTypes.Add($ctToAdd)
write-host "Content type" $ct.Name "added to list" $docLibrary.Title
$docLibrary.Update()
}
else
{
write-host "The list" $lookForList "does not exist in site" $siteA.Title
}
#Dispose of the site object
$site.Dispose()