Today I will share with you some nice PS snippets to change Master Page for all sites in the site collection. And if your read the entire post you can save a lot of time, not to mention the time used by the Branders to manually publish their CSS and master page. (ooooops, suddenly I have the entire SP Branding industry on my back 🙂 )

Let`s go:
This first PS script will work on publishing sites, and non publishing sites. If you have a custom master page, just replace V4.master with your custom name.

$site = Get-SPSite http://intranet
foreach ($web in $site.AllWebs) {
$web; $web.CustomMasterUrl = "/_catalogs/masterpage/V4.master"; 
$web.Update(); $web.CustomMasterUrl;
$web.Dispose()
}
foreach ($web in $site.AllWebs) {
$web; $web.MasterUrl = "/_catalogs/masterpage/v4.master"; 
$web.Update(); $web.MasterUrl;
$web.Dispose()
}
$site.Dispose()
write-host "May the force the with you! V4 Masterpage is now applied…";

… Nice… 🙂
->If you are even more lazy then me (if possible..) than feel free to copy with pride the following snippets to set alternate CSS on the top site:

$web = Get-SPWeb http://intranet
$web.AlternateCssUrl = "/Style Library/MyStyles/main.css"
$web.AllProperties["__InheritsAlternateCssUrl"] = $True
$web.Update()

Publishing sub sites will inherit… sweet….
The next  trick might come in handy if you are a foreigner, as in from Europe or Norway (like me), this snippet will set locale regional web settings to Norwegian Bokmaal:

$site = Get-SPSite http://intranet
foreach ($web in $site.AllWebs) {
$web; $web.Locale = 1044; 
$web.Update(); $web.Locale;
$web.Dispose()
}
$site.Dispose()

And finally, why not associate the one logo to all sites in the site collection. (Hurraaii sais the CMO)

(get-spsite http://intranet).AllWebs | foreach {
$_.SiteLogoUrl = "/style library/Images/R2D2.png";

 
This is a taste of Atea Rapid SharePoint…

by Thorbjørn Værp on Nov 28, 2012 at 9:27 PM

tagged:

Leave a Reply