locked
setting the custom master page through powershell is NOT working RRS feed

  • Question

  • Hi,

     I am writing the below code to set the  custom master page through powershell.

    But its not working .when i went to site settings-->master page --> in the drodown , the  maste page set is seattle.master ONLY, though my current master page is available in the dropdown.

     Can anyone pls help, whether i am missing in the below :

          Add-PSSnapin Microsoft.SharePoint.Powershell
           $SiteURL = "http://srvr1:22307/sites/SPW5"
        $weburl= $SiteURL
        $Site= Get-SPSite $SiteURL
        $web =  $Site.OpenWeb()

    $web.CustomMasterUrl = "/_catalogs/masterpage/myMasterpage.master"
    $web.MasterUrl = "/_catalogs/masterpage/myMasterpage.master"
    $web.Update()
       


    Das



    • Edited by DADasRF Wednesday, January 7, 2015 7:15 AM
    Wednesday, January 7, 2015 7:07 AM

Answers

  • Hi,

    Is it a publishing page? If yes can you try the PowerShell scripts corresponding to the following code snippet?

    var publishingWeb = PublishingWeb.GetPublishingWeb(web);
    publishingWeb.CustomMasterUrl.SetInherit(inheritFromParent, false);
    publishingWeb.CustomMasterUrl.SetValue(masterPageUrl, false);
    publishingWeb.MasterUrl.SetInherit(inheritFromParent, false);
    publishingWeb.MasterUrl.SetValue(masterPageUrl, false);
    

    I've noticed sometime (not sure though) that Master page doesn't get updated if the inherit property is not updated first.


    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com

    • Proposed as answer by Patrick_Liang Thursday, January 15, 2015 12:39 PM
    • Marked as answer by Patrick_Liang Sunday, January 18, 2015 9:46 AM
    Wednesday, January 7, 2015 7:49 AM

All replies

  • Hi,

    Is it a publishing page? If yes can you try the PowerShell scripts corresponding to the following code snippet?

    var publishingWeb = PublishingWeb.GetPublishingWeb(web);
    publishingWeb.CustomMasterUrl.SetInherit(inheritFromParent, false);
    publishingWeb.CustomMasterUrl.SetValue(masterPageUrl, false);
    publishingWeb.MasterUrl.SetInherit(inheritFromParent, false);
    publishingWeb.MasterUrl.SetValue(masterPageUrl, false);
    

    I've noticed sometime (not sure though) that Master page doesn't get updated if the inherit property is not updated first.


    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com

    • Proposed as answer by Patrick_Liang Thursday, January 15, 2015 12:39 PM
    • Marked as answer by Patrick_Liang Sunday, January 18, 2015 9:46 AM
    Wednesday, January 7, 2015 7:49 AM
  • hi Sohel,

     may i know whats meant by "inheritFromParent"


    Das

    Wednesday, January 7, 2015 8:59 AM
  • try these links:

    https://gallery.technet.microsoft.com/office/Set-custom-pages-to-all-d6d66dc5

    http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=226

    http://sharepoint.stackexchange.com/questions/73857/code-for-updating-the-master-page-powershell-2013

    Wednesday, January 7, 2015 10:48 AM
  • Hi Das,

    First parameter 'inheritFromParent' is the actual value - 'true' or 'false'. The second parameter is also boolean which is whether to force the inherit value to subsites. You can find the details if you try the API is visual studio.


    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com

    Thursday, January 8, 2015 1:52 AM
  • adding full script to Sohel Rana

    #Get the Web
    $url = $Site + "/" + $webTitle
    $web = Get-SPWeb $url
     
    write-host "load publishing site - can take a minute"
    $publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
    write-host "set master"
    $masterPageUrl = "/" + $webTitle + "/_catalogs/masterpage/XXX.master"
    #Set Default and Custom Master pages
    $publishingWeb.CustomMasterUrl.SetInherit($true$true);
    $publishingWeb.CustomMasterUrl.SetValue($masterPageUrl$true);
    $publishingWeb.MasterUrl.SetInherit($true$true);
    $publishingWeb.MasterUrl.SetValue($masterPageUrl$true);
    #Apply Changes
    write-host "update changes"
    $publishingWeb.Update()

    Monday, February 10, 2020 1:47 PM