SharePoint Online: Page layouts 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: Adding Page Layout (e.g: Inherit from Article Page)

$ct = Get-SPOContentType -Identity "Article Page"
Add-SPOPublishingPageLayout -SourceFilePath "Path to your page layout aspx" `
                            -Title "Test layout" -Description "Test Page Layout" `
                            -AssociatedContentTypeID $ct.Id

Example: Retrieving Page Layout

Get-SPOListItem -List "Master Page Gallery" `
                -Query "<View><Query><Where><Contains><FieldRef Name='Title'/><Value Type='Text'>Test Layout</Value></Contains></Where></Query></View>"

Example: Deleting Page Layout

Will not be able to be deleted if any pages is using the page layout)

$layout = Get-SPOListItem -List "Master Page Gallery" `
                          -Query "<View><Query><Where><Contains><FieldRef Name='Title'/><Value Type='Text'>Test Layout</Value></Contains></Where></Query></View>"

Remove-SPOListItem -List "Master Page Gallery" -Identity $layout
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