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. https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/add-pnpclientsidepage?view=sharepoint-ps
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. https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/set-pnplistitem?view=sharepoint-ps
$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.
Is there a way to change the Parent Page property?
Example: I want to set the page’s Parent Page to home.aspx
you can update the page properties by getting the page as an item, and updating the properties.
https://pnp.github.io/powershell/cmdlets/Set-PnPListItem.html
Hello, you can get the created page Id like this:
$newPage = Add-PnPPage …
$newPage.PageListItem.Id
Very Informative posts .It helps us to set custom page properties .Thanks for sharing 🙂