SharePoint Online: Approve Pages in Pending Status using PnP PowerShell

When publishing is enabled in SharePoint Online, all the edits of the documents/pages will have the minor versions (or drafts). All changes to any document isn’t available to users with read only permissions, until its Published. Published documents becomes major versions such as 1.0, 2.0, 3.0, etc.

Document will have multiple statuses: Scheduled, Draft, Pending, and Approved.

You can publish the individual document by right click on the document to publish –> In the context menu, choose More –> and then click on Publish.

You can use PowerShell to Publish multiple documents at ones:

 
#################################################################################################### 
# 
# Author.......: David Shvartsman 
# Date.........: 05/07/2021 
# Description..: SharePoint Online: Approve Pages in Pending Status using PnP PowerShell 
# 
####################################################################################################
CLS
$SiteURL = "https://contoso.sharepoint.com/sites/site1"
$LibraryName ="Library1"

Write-host "Processing $($SiteURL) ..."
Connect-PnPOnline -Url $SiteURL -Credentials $credential -IgnoreSslErrors

#Get All Files from the document library - In batches of 500 and _ModerationStatus equel 2 (Approval Status: Pending)
$ListItems = Get-PnPListItem -List $LibraryName -PageSize 500 | Where {$_["_ModerationStatus"] -eq 2} 
$DocumentsData=@()
Write-host "Number of items found in '$($LibraryName)' $($ListItems.count)"
ForEach($Item in $ListItems)
{
    #Collect Documents Data
    $DocumentsData += New-Object PSObject -Property @{
        FileName = $Item.FieldValues['FileLeafRef']
        FileURL = $Item.FieldValues['FileRef']
        Status = $Item.FieldValues._ModerationStatus
    }
    Set-PnPFileCheckedIn -Url $Item.FieldValues['FileRef'] -CheckinType OverwriteCheckIn -Comment "Automated Approval" -Approve
}
$DocumentsData | Export-csv "C:\temp\PendingPages.csv"


Write-host "Processing $($SiteURL) completed."
Write-host ""
Write-host ""
Write-host ""
Write-host ""

###################################################################################################

The values of ‘_ModerationStatus’ property are:

0 – Approved

2 – Pending

3 – Draft

4 – Scheduled

You can use the script to select pages in different Approval Status and Approve and/or Publish those using Set-PnPFileCheckedIn PnP command.

That was another page in the Chronicles of SharePoint Bits, happy scripting!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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