Recently I had to provision a number of modern pages w/ some additional page properties. These page properties were custom fields added as columns to the Site Pages library. I found it somewhat annoying that there was not direct way to provision a page via PnP PowerShell with properties.

This blog covers the 2 steps w/ code on creating a new modern page (aka client side page) and then getting that page as a list item and updating its properties.

Step 1 of creating the page is very simple but, as you can see, you cannot supply additional values for custom properties.

Add-PnPClientSidePage -Name "My New Page" -PromoteAs NewsArticle -Publish

Step 2 is to find the page and then update it as a list item. In case you didn’t know, everything inside the -Values @{} are your custom properties.

$page = Get-PnPListItem -List "Site Pages" -Query "<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>My New Page</Value></Eq></Where><RowLimit>1000</RowLimit></Query></View>"

Set-PnPListItem -List "Site Pages" -Identity $page.ID -Values @{"Title"="My New Page";"Classification"="News";"Article_x0020_Date"=$startDateTime.AddDays($i); "LocationTag"="Enterprise Taxonomy|Locations|$location";}

I was unable to find a command-let to just get me the page by title. This CAML query should help you out.

  • HD
    Posted at 5:19 pm November 29, 2022

    Is there a way to change the Parent Page property?

    Example: I want to set the page’s Parent Page to home.aspx

  • Alberto
    Posted at 4:23 pm November 3, 2022

    Hello, you can get the created page Id like this:
    $newPage = Add-PnPPage …

  • pooja
    Posted at 8:58 pm June 1, 2020

    Very Informative posts .It helps us to set custom page properties .Thanks for sharing 🙂

  • Leave a Reply to pooja
    Cancel Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.