[SPO] Create a new Page Library and copy items from the old page library

WARNING: Microsoft supports Site Pages libraries created through either calling EnsureClientRenderedSitePagesLibrary(), EnsureSitePagesLibrary(), or by activating the Site Pages feature (which does the first one internally). These methods all create the library correctly, with the right content types, and with the web-relative URL of /SitePages/.

 

The below article is just for your info only!

SitePages has the following FeatureID: b6917cb1-93a0-4b97-a84d-7cf49975d4ec

 

So on with PnP:

In order to create the new Page library we have to take into consideration that the Page Library template is 119

So, here goes:

and here is the result:

Now we see that compared to the original Site Pages library, we are missing a content type: named “Site Page”

So let’s add the Site Page content type:

you’ll see the content type added:

and we need to remove the “Wiki Page” content type:

and here are the final results:

OK, now that we have the library created, we need to copy the items from the old site pages library to our new library:

 

and the results:

The logic is even simpler for a single file:

Now to rename the newly created Page Library we can use:

and the results:

To just change the list’s name you can use the following script: (bear in mind that the list’s URL won’t change)

To remove the old or any list, you can always use:

Enjoy!