Update Master Page of SharepointSite Using PowerShell

Hi

In this post i have written about how to Update master page of any site of SharePoint.
It can also achieve through OOTB within few click, but it can also achieve using powershell

$site = Get-SPSite http://sp:2000/sites/Ex15
foreach ($web in $site.AllWebs)
{
    $web.MasterUrl = $site.RootWeb.ServerRelativeUrl +  "/_catalogs/masterpage/oslo.master";
    $web.CustomMasterUrl = $site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/oslo.master";
    $web.Update();
    Write-Host $web.Url $web.MasterUrl $web.CustomMasterUrl;
}
$site.Dispose()

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
    #Get All site collections
    $SiteCollections = Get-SPWebApplication | Get-SPSite -Limit All
    #Loop through all site collections
       foreach($Site in $SiteCollections)
        {
            #Loop throuh all Sub Sites
           foreach($Web in $Site.AllWebs)
           {
		$web.MasterUrl = $site.RootWeb.ServerRelativeUrl +  "/_catalogs/masterpage/oslo.master";
		$web.CustomMasterUrl = $site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/oslo.master";
		$web.Update();
		Write-Host $web.Url $web.MasterUrl $web.CustomMasterUrl;
           }
        }

Thanks
SPS

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s