How do I apply a custom master page via PowerShell

Start → Right click on SharePoint 2013 Management Shell → Run as different user

  • Login :Domain\SP-Farm
  • Password : ******


Then Enter this script :


$site = new-object Microsoft.SharePoint.SPSite("http://Sharepoint")
$web = $site.OpenWeb("/MySite")

# To apply a master page on native pages (default)

$web.MasterUrl = "/_catalogs/masterpage/myMasterPage.master"

# To apply a master page on custom pages

$web.CustomMasterUrl = "/_catalogs/masterpage/myMasterPage.master"

$web.Update()

$web.Dispose()

Enregistrer un commentaire