SharePoint Online: Master Page Operation with PnP Powershell

First, you will have to connect to your SharePoint Online Site

Example: Connect to SPO

$siteurl = "https://yourspsite.sharepoint.com"  
Connect-SPOnline -Url $siteurl  
$ctx = Get-SPOContext  

Example: How to add master page

Add-SPOMasterPage -SourceFilePath "e.g: C:\temp\" -Title "master.aspx" `
                  -Description "Custom master page" `
                  -DestinationFolderHierarchy "Temp" -UiVersion 15

Example: Update master page settings

$MasterPageServerRelativeUrl = "/_catalogs/masterpage/Temp/master.aspx"
Set-SPOMasterPage -MasterPageServerRelativeUrl $MasterPageServerRelativeUrl `
                  -CustomMasterPageServerRelativeUrl $MasterPageServerRelativeUrl

Example: Update master page settings on subsites

$subWebs = Get-SPOSubWebs
$MasterPageServerRelativeUrl = "/_catalogs/masterpage/Temp/master.aspx"
foreach ($web in $subWebs) {
	Set-SPOMasterPage -MasterPageServerRelativeUrl $MasterPageServerRelativeUrl `
	                  -CustomMasterPageServerRelativeUrl $MasterPageServerRelativeUrl `
			  -Web $web.ServerRelativeUrl
}
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