SOLVED

How to publish all pages in SitePages library?

%3CLINGO-SUB%20id%3D%22lingo-sub-251117%22%20slang%3D%22en-US%22%3EHow%20to%20publish%20all%20pages%20in%20SitePages%20library%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-251117%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%204%20500%20modern%20pages%20in%20my%20pages%20library%20and%20all%20are%20minor%20versions.%20I%20need%20to%20publish%20all.%20Does%20anyone%20have%20a%20PowerShell%20script%20for%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-251137%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20publish%20all%20pages%20in%20SitePages%20library%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-251137%22%20slang%3D%22en-US%22%3E%3CP%3EExactly%20what%20I%20was%20looking%20for.%20Thanks%20for%20your%20quick%20reply.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-251128%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20publish%20all%20pages%20in%20SitePages%20library%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-251128%22%20slang%3D%22en-US%22%3E%3CP%3EPnP%20PowerShell%20is%20the%20way%20I%20always%20find%20easiest%20for%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EConnect-PnPOnline%20-Url%20%22%3CYOUR%20site%3D%22%22%20url%3D%22%22%20here%3D%22%22%3E%22%3CBR%20%2F%3E%3CBR%20%2F%3E%24pageslib%20%3D%20Get-PnPList%20-Identity%20%22Site%20Pages%22%3CBR%20%2F%3E%3CBR%20%2F%3E%24pages%20%3D%20Get-PnPListItem%20-List%20%24pageslib%3CBR%20%2F%3E%3CBR%20%2F%3Eforeach(%24page%20in%20%24pages)%7B%3CBR%20%2F%3E%20%24page.File.Publish(%22Published%22)%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3EInvoke-PnPQuery%3C%2FYOUR%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1926296%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20publish%20all%20pages%20in%20SitePages%20library%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1926296%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F177418%22%20target%3D%22_blank%22%3E%40Matt%20Weston%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EHi%2C%20what%20should%20I%20add%20on%20this%20script%20to%20allow%20the%20same%20result%20for%20list%20with%20more%20than%205000%20items%3F%20I%20am%20getting%20list%20view%20threshold%20error.%20I%20am%20on%20SharePoint%20Online.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ryan_Linsangan_0-1606210743971.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F235742iD36D201B2F83381B%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Ryan_Linsangan_0-1606210743971.png%22%20alt%3D%22Ryan_Linsangan_0-1606210743971.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

I have 4 500 modern pages in my pages library and all are minor versions. I need to publish all. Does anyone have a PowerShell script for this?

3 Replies
best response confirmed by Papageno Sweden (Occasional Contributor)
Solution

PnP PowerShell is the way I always find easiest for this:

 

Connect-PnPOnline -Url "<your site url here>"

$pageslib = Get-PnPList -Identity "Site Pages"

$pages = Get-PnPListItem -List $pageslib

foreach($page in $pages){
$page.File.Publish("Published")
}

Invoke-PnPQuery

Exactly what I was looking for. Thanks for your quick reply.

@Matt Weston 

Hi, what should I add on this script to allow the same result for list with more than 5000 items? I am getting list view threshold error. I am on SharePoint Online. 

Ryan_Linsangan_0-1606210743971.png