Search This Blog

Tuesday, August 27, 2013

How to set a SharePoint Custom Master Page for all webs in a Site Collection using Powershell

How to set all webs (sub sites as some call them) in a site collection, to use a common master page?

$site = Get-SPSite http://portal.somewhere.com/ 
$sites = @(foreach ($web in $site.AllWebs) { 
$web | Select-Object -Property Url 
Write-Debug "Setting master pages in web ($($web.Url))..." 
$web.MasterUrl = "/_catalogs/masterpage/your_custom_page.master" 
$web.Update() 
$web.Dispose() 
}) | out-File -filepath "c:\masterpagesmodifiedOutput.txt" 
$site.Dispose() 

To Run It
Save the above after you have customized it as pushmasterpages.ps1 (using notepad, or whatever…)
Open SharePoint 2010 Management Shell (Powershell)
Launch Powershell against that file (assuming it is in the root of C:), that would be:
.\pushmasterpages.ps1

No comments:

Post a Comment