Upload Master Page to SharePoint using PowerShell

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

PowerShell script to upload Master page to SharePoint:

Have you ever created a master page in SharePoint and uploaded it to your sites? Wouldn’t it be nice if there was an easy way to upload your master page to SharePoint instead of manually doing it? Well, there is! This blog post will show you how to use PowerShell to upload your master page.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$WebURL = "https://intranet.crescent.com/"
$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 the master page to SharePoint from the 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

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

One thought on “Upload Master Page to SharePoint using PowerShell

  • The master page list can be retrieved with

    $MasterPagelist = ($web).Lists |? {$_.Title -eq “Master Page Gallery”}

    Your way not works for me (Sharepoint 2013)


Leave a Reply

Your email address will not be published. Required fields are marked *