1

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?

0

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()
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.