Sunday, March 23, 2014

Change Master Page in SharePoint using PowerShell

Requirement: Change Master page for SharePoint Site collections.

After a branding redesign project, Got a requirement to change master pages on existing sites. branding on new sites going to be created. But for existing sites, We got to change master pages manually.

SharePoint 2013 set master page using PowerShell:
Lets change master page in SharePoint 2010 using PowerShell.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

#Get the Web
$web = Get-SPWeb "https://intranet.crescent.com/branding"

#Prepare the Custom Master page URL
$WebURL = $web.ServerRelativeUrl.TrimEnd("/")
$MasterPageURL = $WebURL+"/_catalogs/masterpage/crescentv1.master"

#Set Default and Custom Master pages
$web.MasterUrl = $MasterPageURL
$web.CustomMasterUrl = $MasterPageURL

#Apply Changes
$web.Update() 

How about All sites in a site collection?Here is the PowerShell script in SharePoint 2013 to change master page.
#Variable for Site collection
$SiteURL ="http://intranet.crescent.com"

#Get the Site object
$site = Get-SPSite $SiteURL

#Iterate through each web
foreach ($web in $site.AllWebs)
{
 #Prepare the Custom Master page URL
 $WebURL = $web.ServerRelativeUrl.TrimEnd("/")
 $MasterPageURL = $WebURL+"/_catalogs/masterpage/crescentv1.master"

 $web.MasterUrl = $MasterPageURL;
 $web.CustomMasterUrl = $MasterPageURL;
 
 $web.Update();

    Write-Host "Master page set for: $web.Url
}
We can modify the above code to apply master page for entire web application, even entire SharePoint farm!

Tags: sharepoint 2013 apply master page powershell, sharepoint powershell apply master page sharepoint 2010, powershell apply master page sharepoint, change master page powershell, sharepoint 2013 change master page powershell, set master page powershell sharepoint 2013, change master page sharepoint 2013 using powershell



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...