How to Add new content type to SharePoint Document Library using Powershell

$site = Get-SPSite SiteURL

foreach($web in $site.AllWebs){

 $listCounter = $web.Lists.Count
 for($i=0;$i -le $listCounter;$i++) {

 $list = $web.Lists[$i]
     if($list.BaseType -eq "DocumentLibrary") {
     $newList = $web.Lists.item($list.ID);

        $newList.ContentTypesEnabled = $true
        $newList.Update()
   
        #Add site content types to the list
        $ctToAdd = $site.RootWeb.ContentTypes["New Excel"]
        $ct = $newList.ContentTypes.Add($ctToAdd)
        write-host "Content type" $ct.Name "added to list" $newList.Title
        $ctToAdd = $site.RootWeb.ContentTypes["New PowerPoint"]
        $ct = $newList.ContentTypes.Add($ctToAdd)
        write-host "Content type" $ct.Name "added to list" $newList.Title
        $newList.Update()
 }
 }
 $web.Dispose();
     }

$site.Dispose();

Comments

Popular posts from this blog

IRM and the Object Model

This content database has a schema version which is not supported in this farm

Activate and Deactivate Feature through PowerShell