Powershell – change masterpage for your SharePoint site

This will work on both 2007 and 2010 version

 

 

[sourcecode language="powershell"]
$Host_URL = "http://portal"
$web = Get-SPWeb $Host_URL

if ($web.ServerRelativeUrl -eq "/")
{
$web.CustomMasterUrl =  "/_catalogs/masterpage/horsik.master"
$web.MasterUrl =  "/_catalogs/masterpage/horsik.master"
}
else
{
$web.CustomMasterUrl = $web.ServerRelativeUrl+ "/_catalogs/masterpage/horsik.master"
$web.MasterUrl = $web.ServerRelativeUrl+ "/_catalogs/masterpage/horsik.master"
}
$web.Update()

[/sourcecode]

2 Responses to “Powershell – change masterpage for your SharePoint site”

  1. Ali

    “This will work on both 2007 and 2010 version”

    Get-SPWeb will not work on SharePoint 2007. You will have to change your code a bit.

    Reply
  2. horsik

    Ali is right, this powershell script will not work on SharePoint 2007, corresponding API C# code would.

    Reply

Leave a Reply