How to apply Master Page for all Site Collections using PowerShell


Shreyan Advisory

When we have our own custom master pages, we can apply that master page to site collection via PowerShell. The other important thing is, we can set master page to all sites / sub-sites via one command line.

Set Master Page

foreach ($site in get-spsite -url http://spsvr*) {

     $web = Get-SPWeb $site

     $web.CustomMasterUrl = “/_catalogs/masterpage/my_v4.master”

     $web.Update()

}

Using another method

foreach ($site in Get-SPSite)

{

foreach ($web in $Site.AllWebs)

{

$web.MasterUrl = “/_catalogs/masterpage/my_v4.master”;

$web.CustomMasterUrl = “/_catalogs/masterpage/my_v4.master”;

$web.update()

}

}

Set Master Page for Web Application

#Enter a web application, get all the site collections in the web app

Add-PsSnapin Microsoft.SharePoint.PowerShell

Start-SPAssignment -Global

$web = Get-SPWeb ‘http://spsvr:1111/’

#$web.CustomMasterUrl = “/_catalogs/masterpage/v4_TG.master”

$web.MasterUrl = “/_catalogs/masterpage/v4_TG.master”

$web.Update()

Set Master Page for All Sub sites

#Enter a web application, get all the site collections in the web app

Add-PsSnapin Microsoft.SharePoint.PowerShell

Start-SPAssignment -Global

$site = Get-SPSite ‘http://spsvr:1111’

$topWeb = Get-SPWeb $site.Url

$site…

View original post 50 more words