Thursday 10 January 2013

Activate MasterPage using Poweershell Script in SharePoint 2010


After deploying the custom Master Page we need to activate the Master Page for the particular site collection. After Activating the Custom Master Page, these are now visible in the Master Pages tab in Site Actions – Site Settings – Galleries – Master Pages. To set the custom Master Page as Default Master Page in SharePoint Foundation 2010, the user has to set it through SharePoint Designer. The User can also set the custom Master Page as Default using the following Powershell Script:

//For Single Site 

$web = Get-SPWeb http://sitename
$web.CustomMasterUrl = "/_catalogs/masterpage/custommasterpagename.master"
$web.MasterUrl = "/_catalogs/masterpage/custommasterpagename.master"
$web.Update()


//For All sites & Subsites within the site collection

$site = Get-SPSite -Identity http://sitename
foreach($subsite in $site.AllWebs)
{
    $subsite.AllowUnsafeUpdates = "True"
    $subsite.CustomMasterUrl = "/_catalogs/masterpage/custommasterpagename.master"
    $subsite.Update()
    $subsite.AllowUnsafeUpdates = "False"
    $subsite.Dispose()
}

No comments:

Post a Comment