0

I am on SharePoint Online environment and am trying to change page layouts of all pages with in a Publishing site. By default the page layout is basic and am trying to change all pages to use a custom layout that I built. I am able to do so manually but I want to do it using PowerShell.

I am using this code on https://www.sharepointwidgets.com/2019/02/powershell-script-to-update-page-layout.html but I get a this error,

Exception Happened on getAllPages : + Cannot bind argument to parameter 'Url' because it is an empty string.

Not really sure, why that's happening as I am passing the parameters [string]$targetSiteURL = Read-Host "xxxxxxxxxxxxxxx" [string]$newPageLayoutTitle = "Custom Page" [string]$oldPageLayoutTitle = "Basic Page"

Please suggest or help with me with another solution.

Thanks.

1 Answer 1

0

SharePoint Online Modern page layouts:

  • Home Page Layout
  • Article Page Layout
  • Single Part App Page

Please run the following PnP PowerShell script:

Write-Host "Type the site collection URL:"
$siteCollectionURL = Read-Host
 
Write-Host "Type the page name:"
$PageName = Read-Host
 
Write-Host "Choose the page layout:"
        
Write-Host "1 - Home"
Write-Host "2 - Article"
Write-Host "3 - Single Web Part App Page"
$option = Read-Host
 
if($option -eq "1"){
    $option = "Home"
}elseif($option -eq "2"){
    $option = "Article"
}elseif($option -eq "3"){
    $option = "SingleWebPartAppPage"
}
 
Connect-PnPOnline -Url $siteCollectionURL  
Set-PnPClientSidePage -Identity $PageName -LayoutType $option

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.