Friday, May 23, 2014

Upload Master Page to SharePoint using PowerShell

We've a SharePoint 2013 master page from a third-party consultants and would like copy-apply the master page to SharePoint sites.

PowerShell script to upload Master page to SharePoint:

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$WebURL = ""
$MasterPage = "Crescentv1.master"
$SourcePath ="D:\Branding\MasterPages\Crescentv1.master"

#Get the Web
$web = Get-SPWeb $WebURL

#Get the Target folder - Master page Gallery
$MasterPageList = $web.GetFolder("Master Page Gallery")

#Set the Target file for Master page
$TargetPath = $Web.Url + "/_catalogs/masterpage/Crescentv1.master"

#Get the Master page from local disk 
$MasterPageFile = (Get-ChildItem $SourcePath).OpenRead()

 #Check if file exist already
 if ($Web.GetFile($TargetPath).Exists)

    #upload master page using powershell
    $MasterPage = $MasterPageList.Files.Add($TargetPath,$MasterPageFile,$false)
This script copies master page to SharePoint from local disk. Just wrap the code inside a loop to copy the master page to all sites. Once uploaded, we can Set the master page with another PowerShell script:  Change Master Page in SharePoint using PowerShell

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

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...