1

I'm trying to automate our cie theme with powershell. So far I succeeded in uploading master page and page layouts to the masterpage gallery, check them in and publish them. Now I want to change the content type of masterpages uploaded for "Master Page" since it is set as "Creation file" as default when uploaded. I also want to change the content type of page layouts to "Page layout" and their associated content type to our custom content type.

The code below find the right content type but doesn't seem to update the layouts, when I check the property of them in the master page gallery, it's still "Creation file"

    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue   
## Add Microsoft.SharePoint.Publishing assembly
Add-Type -Path 'C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Publishing.dll';

$SiteCollectionUrl = "https://example.org/sites/blankDesign"
$baseSite = "https://example.org"
$SiteUrl = 'blankDesign';
$masterPageCatalog = "_catalogs/masterPage"


$site = Get-SPSite $SiteCollectionUrl
$web = $site.OpenWeb() 
$rootWeb = $site.RootWeb;
$folder = $rootWeb.GetFolder($masterPageCatalog)
$masterPageCatList = $rootWeb.Lists[$folder.ParentListId] 
$items = $masterPageCatList.GetItems()



ForEach($ctype in $web.ContentTypes){



    if($ctype.Name.ToLower() -like "*hq*page*wiki"){
        Write-host "Content type des layouts:" $ctype.Name
        $PageWikiCT = $ctype
    }
    if($ctype.Name.ToLower() -like "master*page"){
        Write-host "Content type des master pages:" $ctype.Name
        $MasterPgCT = $ctype
    }
    if($ctype.Name.ToLower() -like "master*page*preview"){
        Write-host "Content type des master pages preview:" $ctype.Name
        $MasterPgPR = $ctype
    }

}

foreach ($item in $items) {

    if($item.Name.ToLower() -like "*hq*wiki*"){


        Write-host $page.Layout.Title
        $item.File.CheckOut()
        $item["ContentTypeId"] = $PageWikiCT.Id
        $item["ContentType"] = $PageWikiCT.Name
        $item.Update()
        $item.File.CheckIn('Checkin')


    }




}
  • OK, I found the problem, I was using the content type found in my loop from web content type. After checking the contenttype ID from OOTB layouts, I found out that the content type is the one I found plus some other characters at then end. I don't get we're those come from but now I get the content type from an existing layout and it works. – Michel Bernier Feb 21 '18 at 13:37
0

OK, I found the problem, I was using the content type found in my loop from web content type. After checking the contenttype ID from OOTB layouts, I found out that the content type is the one I found plus some other characters at then end. I don't get we're those come from but now I get the content type from an existing layout and it works.

|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.