About Me

My photo
a Dynamic and Energetic guy.....

Sunday, January 27, 2013

Apply MasterPage to all Site Collections Using PowerShell Commands

------------------------ 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 Other 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 Subsites --------------
----------------------------------------------------------------------
#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 | Get-SPWeb -limit all | ForEach-Object 
{if (($_.WebTemplate -ne "SRCHCEN") -and ($_.WebTemplate -ne "SRCHCENTERLITE") -and ($_.WebTemplate -ne "SRCHCENTERFAST")) {$_.CustomMasterUrl = $topWeb.CustomMasterUrl;$_.AllProperties["__InheritsCustomMasterUrl"] = "True";$_.MasterUrl = $topWeb.MasterUrl;$_.AllProperties["__InheritsMasterUrl"] = "True";$_.AlternateCssUrl = $topWeb.AlternateCssUrl;$_.AllProperties["__InheritsAlternateCssUrl"] = "True";$_.Update();}}
Stop-SPAssignment -Global

1 comment:

Vicky Spence said...

How do I call the location of the new custom master page for a full Web Application and Sub Site deployment? I'm not seeing that in the script....

My Masters