Free SharePoint tools · Read-only PnP PowerShell script

Report content approval and draft versions in SharePoint document libraries

Before you switch on AI search or an AI assistant, this script shows which document libraries hold files whose latest version is not approved or not published. Run it for one site or a list of sites with an account that can see draft versions, for example a site owner or a user with the Approve Items permission.

Read only · PnP PowerShell · tested 2026-12-01 · MIT License

What the script reports

For every visible document library the script reports:

  • Versioning settings: versioning on or off, major and minor (draft) versions, version limits
  • Whether content approval is required (EnableModeration)
  • Draft item security (DraftVersionVisibility: Reader, Author or Approver)
  • Number of files, and how many of them have a minor (draft) version as their latest version
  • For libraries with content approval: how many files are Approved, Pending, Rejected, Draft or Scheduled

The result is written to a CSV file, and a short summary is shown in the console. The script is read only. It does not change any setting, file or version.

Before you run it

  • Never used PowerShell? Read Start here, or run this check with an AI assistant.
  • PowerShell 7 (opens in a new tab)
  • PnP PowerShell (opens in a new tab)
  • An Entra ID app registration for PnP PowerShell interactive login. If you do not have one, see Register-PnPEntraIDAppForInteractiveLogin.
  • Run the script with an account that can see draft versions in the libraries, for example a site owner or a user with the Approve Items permission. Draft and pending files are hidden from users who are not allowed to see drafts, so with a reader account the counts can be lower than the real numbers.

How to run it

Save the script as Get-LibraryApprovalReport.ps1 and run it with your site addresses and the client ID of your app registration:

.\Get-LibraryApprovalReport.ps1 -SiteUrls "https://contoso.sharepoint.com/sites/Quality","https://contoso.sharepoint.com/sites/Projects" -ClientId "00000000-0000-0000-0000-000000000000"

The script

<#
.SYNOPSIS
    Read-only report of versioning, content approval and draft status for every
    document library in one or more SharePoint sites.
#>
[CmdletBinding()]
param (
    [Parameter(Mandatory = $true, HelpMessage = "One or more site URLs, e.g. https://contoso.sharepoint.com/sites/Quality")]
    [string[]]$SiteUrls,

    [Parameter(Mandatory = $true, HelpMessage = "Client ID of your Entra ID app registration for PnP PowerShell")]
    [string]$ClientId,

    [Parameter(Mandatory = $false)]
    [string]$OutputPath = (Join-Path (Get-Location) ("library-approval-report-{0}.csv" -f (Get-Date -Format "yyyyMMdd-HHmm")))
)

# _ModerationStatus values: 0 Approved, 1 Denied (Rejected), 2 Pending, 3 Draft, 4 Scheduled
$report = @()

foreach ($siteUrl in $SiteUrls) {
    Write-Host "Connecting to $siteUrl" -ForegroundColor Cyan
    Connect-PnPOnline -Url $siteUrl -ClientId $ClientId -Interactive

    # Load the extra properties per library: loading them for all lists at once can fail with
    # "Access denied" on system lists the account cannot read in full.
    $libraries = Get-PnPList | Where-Object { $_.BaseTemplate -eq 101 -and $_.Hidden -eq $false }

    foreach ($listInfo in $libraries) {
        $library = Get-PnPList -Identity $listInfo.Id -Includes EnableVersioning, EnableMinorVersions, EnableModeration, DraftVersionVisibility, MajorVersionLimit, MajorWithMinorVersionsLimit, RootFolder
        Write-Host "  Reading $($library.Title)" -ForegroundColor Yellow

        $files = 0; $latestIsMinor = 0
        $approved = 0; $rejected = 0; $pending = 0; $draft = 0; $scheduled = 0

        $items = Get-PnPListItem -List $library -PageSize 2000 -Fields "FSObjType", "_UIVersionString", "_ModerationStatus"

        foreach ($item in $items) {
            # Skip folders, count files only
            if ($item.FieldValues["FSObjType"] -ne 0) { continue }
            $files++

            $version = [string]$item.FieldValues["_UIVersionString"]
            if ($version -and -not $version.EndsWith(".0")) { $latestIsMinor++ }

            if ($library.EnableModeration) {
                switch ([int]$item.FieldValues["_ModerationStatus"]) {
                    0 { $approved++ }
                    1 { $rejected++ }
                    2 { $pending++ }
                    3 { $draft++ }
                    4 { $scheduled++ }
                }
            }
        }

        $report += [PSCustomObject]@{
            SiteUrl                     = $siteUrl
            Library                     = $library.Title
            LibraryUrl                  = $library.RootFolder.ServerRelativeUrl
            EnableVersioning            = $library.EnableVersioning
            EnableMinorVersions         = $library.EnableMinorVersions
            MajorVersionLimit           = $library.MajorVersionLimit
            MajorWithMinorVersionsLimit = $library.MajorWithMinorVersionsLimit
            EnableModeration            = $library.EnableModeration
            DraftVersionVisibility      = $library.DraftVersionVisibility
            Files                       = $files
            LatestIsMinor               = $latestIsMinor
            Approved                    = if ($library.EnableModeration) { $approved } else { "" }
            Pending                     = if ($library.EnableModeration) { $pending } else { "" }
            Rejected                    = if ($library.EnableModeration) { $rejected } else { "" }
            Draft                       = if ($library.EnableModeration) { $draft } else { "" }
            Scheduled                   = if ($library.EnableModeration) { $scheduled } else { "" }
        }
    }
}

$report | Export-Csv -Path $OutputPath -Encoding utf8

# Short summary in the console
$report | Format-Table Library, EnableModeration, EnableMinorVersions, DraftVersionVisibility, Files, LatestIsMinor, Approved, Pending, Rejected -AutoSize

$withApproval = @($report | Where-Object { $_.EnableModeration })
$notApproved  = ($withApproval | Measure-Object -Property Pending -Sum).Sum + ($withApproval | Measure-Object -Property Rejected -Sum).Sum + ($withApproval | Measure-Object -Property Draft -Sum).Sum
Write-Host ("Libraries: {0}, with content approval: {1}" -f $report.Count, $withApproval.Count) -ForegroundColor Green
Write-Host ("Files: {0}, latest version is minor (draft, pending or rejected): {1}" -f ($report | Measure-Object -Property Files -Sum).Sum, ($report | Measure-Object -Property LatestIsMinor -Sum).Sum) -ForegroundColor Green
Write-Host ("Files not approved in libraries with content approval (pending, rejected or draft): {0}" -f $notApproved) -ForegroundColor Green
Write-Host "Report saved to $OutputPath" -ForegroundColor Green

Run this check with an AI assistant

Never used PowerShell? Copy this prompt into a new chat in the Claude app, ChatGPT or Microsoft Copilot. The assistant asks what you already have and guides you one command at a time. It cannot run anything on your computer: you paste each command into PowerShell yourself and paste the result back. Never paste passwords, sign-in codes or real customer data into the chat.

The full beginner steps, with the installation of PowerShell 7, are on Never used PowerShell? Start here.

You are helping me run a read-only SharePoint report. I have never used PowerShell. You cannot run commands on my computer. I copy each command from you, paste it into my PowerShell window, press Enter and paste the result back to you.

The script is Get-LibraryApprovalReport.ps1 from https://ksj.lv/en/sharepoint-tools/library-content-approval-report/. It changes no setting, file or version. It reports versioning and content approval for every visible document library on the sites I name, saves a CSV file in the current folder named like library-approval-report-YYYYMMDD-HHMM.csv and shows a short summary in the window. The script text is on that page. I will copy it from there, so do not write it yourself. That page is on ksj.lv, the site of SIA KSJ, not a Microsoft page. PnP PowerShell is an open source community module, not a Microsoft product.

Rules for you:
1. First ask what I already have: my operating system and its version, whether PowerShell 7 is installed, whether PnP.PowerShell is installed, whether I have an Application (client) ID, and whether I am a site owner. Wait for my answer.
2. Then guide me one step at a time, one command per message, never two (not even pwsh together with a check). Put one sentence that explains the command directly above it, and any warning or what to paste back below it. Then wait for me to paste the result.
3. Use only the commands below, plus cd and dir for folders. Never suggest commands that change SharePoint or Entra settings. The only exception is the optional app registration command, and only if I say I am allowed to run it. Never remove -SharePointDelegatePermissions "AllSites.Read" from that command.
4. Early on, remind me in these words: never paste passwords, sign-in codes, tokens, client secrets or real customer data, and replace real site addresses and names with contoso before sharing a result. If I offer a password, refuse it.
5. If I see red text or an error, ask me to paste the error text.
6. Before Install-Module and before running the script, ask me to run $PSVersionTable.PSVersion in that same window. If Major is not 7, wait for my answer and then, as a separate step, tell me to type pwsh. A new Terminal or PowerShell window can open the old Windows PowerShell 5.1.
7. After I go to the script folder, ask me to run dir and check that the file name ends with .ps1 and not .ps1.txt.
8. Write commands with the placeholders from this prompt, even if I mention my values. I replace the site address, tenant name and ID myself.
9. If my counts may be incomplete because of my permissions, only suggest asking a site owner to run the report. Never suggest changing permissions.
10. Do not state guesses as facts. If you are not sure what a result means, say so and ask me to paste more of it. Describe only output I can see. Do not predict what a success message looks like. If what I paste does not match the command you gave, ask me to run that exact command again.

Commands, in order:
Install PowerShell 7 on Windows, in "Terminal" or "Windows PowerShell" opened from the Start menu: winget install --id Microsoft.PowerShell --source winget
winget is included in Windows 11 as part of App Installer. Alternative on Windows: download the MSI installer from the GitHub releases page linked on https://learn.microsoft.com/powershell/scripting/install/install-powershell-on-windows and double-click it.
On macOS: download the .pkg file from the releases page linked on https://learn.microsoft.com/powershell/scripting/install/install-powershell-on-macos, double-click it in Finder, then open the Terminal app.
Start PowerShell 7: pwsh (on Windows I can also open "PowerShell 7" from the Start menu)
Right after a winget install, tell me to close the window and open "PowerShell 7" from the Start menu, because an already open window may not find pwsh yet. The PS C:\...> prompt looks the same in PowerShell 7 and Windows PowerShell 5.1, so the proof is the version check below.
Check that Major is 7 and Minor is 4 or higher: $PSVersionTable.PSVersion
Install the module in PowerShell 7, answer Y if asked to trust PSGallery: Install-Module PnP.PowerShell -Scope CurrentUser
The question about an untrusted repository is normal: PSGallery, the PowerShell Gallery, is the central public repository for PowerShell modules, and it is not configured as trusted by default. When it succeeds, it usually prints nothing more and the prompt comes back without red text.
Optional app registration. Creating it needs at least the Application Developer role, and granting the permissions may need a Global Administrator. It opens a browser to sign in. It creates an app registration in Entra ID and, with consent, grants that app the AllSites.Read permission. That is a change in Entra ID, so tell me this before I run it. Tell me to replace yourtenant.onmicrosoft.com with my own tenant name (usually the first part of my SharePoint address, for contoso.sharepoint.com it is contoso.onmicrosoft.com; if I am not sure, I ask my administrator). When it finishes, the Application (client) ID is shown next to AzureAppId/ClientId: Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "PnP read-only checks" -Tenant yourtenant.onmicrosoft.com -SharePointDelegatePermissions "AllSites.Read"
Without -SharePointDelegatePermissions "AllSites.Read" the command registers broad default permissions (SharePoint TermStore.ReadWrite.All, AllSites.FullControl, User.ReadWrite.All; Graph Group.ReadWrite.All, User.ReadWrite.All), so that part must stay.
If I am not an admin, tell me to ask my Microsoft 365 administrator for an app registration for PnP PowerShell interactive login with delegated SharePoint permission AllSites.Read and admin consent, and for its Application (client) ID.
Save the script: copy it from the script page with the Copy button, paste it into Notepad on Windows, or TextEdit on Mac after choosing Format > Make Plain Text, and save it as Get-LibraryApprovalReport.ps1 in a folder such as Documents\scripts (create the scripts folder first if it does not exist). Tell me to check that the file name ends with .ps1 and not .txt.
Go to the folder (works on Windows and Mac): cd $HOME/Documents/scripts
If that folder is not found, ask me where I saved the file and help me go there.
Run: .\Get-LibraryApprovalReport.ps1 -SiteUrls "https://contoso.sharepoint.com/sites/Quality" -ClientId "00000000-0000-0000-0000-000000000000"
SiteUrls takes one address or several, each in its own quotes with a comma between, for example -SiteUrls "https://contoso.sharepoint.com/sites/Quality","https://contoso.sharepoint.com/sites/Projects". ClientId is my Application (client) ID. I type my real values myself. I should sign in as a site owner or a user with Approve Items permission, or the counts can be lower than the real numbers.

When I paste the summary or rows from the CSV file, explain them with these rules:
LatestIsMinor above 0: the latest version of these files is a minor version, not published as major yet. With content approval it also counts pending and rejected files, so do not add it to Draft, Pending or Rejected.
Pending above 0: files are waiting for an approver.
Rejected above 0: the latest version was rejected.
EnableModeration False and EnableMinorVersions False: every saved version is the current version, with no separate approved state.

Tested on 2026-12-04 in a new chat with no other instructions, with simulated beginners: Windows with only the Claude app, a Mac, and a Windows user who runs the script and hits an error. Claude Sonnet 5.5 followed the prompt in 4 of 4 conversations, Claude Haiku 5.5 in 2 of 4. In all 8 it warned against pasting passwords and secrets, and every command it gave was a command from this prompt or a folder listing. In a separate test with real report output, Claude Sonnet 5.5 explained the numbers correctly.

What the result tells you

The script writes the result to a CSV file and shows a short summary in the console. Read these columns first:

  • LatestIsMinor greater than 0: the latest version of these files is a minor version, so it is not published as a major version yet. In a library with content approval this also counts files that wait for approval or were rejected, so do not add it to Draft, Pending and Rejected.
  • Pending greater than 0: these files wait for an approver.
  • Rejected greater than 0: the latest version of these files was rejected.
  • EnableModeration False and EnableMinorVersions False: every saved version is the current version, so there is no separate approved state to rely on.

For a one-page summary that you can print or save as PDF, open the CSV file in the library approval report summary. The file is read in your browser and is not uploaded.

Console output of the SharePoint library content approval report: 15 libraries, 3 with content approval, 1 rejected file
Console output from a test site with sample data, with the site address replaced by contoso.

Tested on

The script was tested on 2026-12-01 on one Microsoft 365 developer tenant site with sample data, using the versions below.

Component Version
PowerShell 7.7.0 (Linux)
PnP.PowerShell 3.5.0
Login Connect-PnPOnline -DeviceLogin -PersistLogin, Entra ID app with delegated SharePoint permission, account is site owner

Results for the test library (content approval and minor versions on):

Run Files LatestIsMinor Approved Pending Rejected Draft Scheduled
Before test data 4 0 4 0 0 0 0
With test data 7 3 4 2 0 1 0
After clean-up 4 0 4 0 0 0 0
With rejected file 5 1 4 0 1 0 0
After clean-up 4 0 4 0 0 0 0

The rows with test data matched an independent REST read of the same files. Not tested: the Scheduled count.

Published under the MIT License. Author: Kaspars Jurjāns, SIA KSJ.

The two-week Answergrove pilot runs these same kinds of checks on one site. Open the pilot form

All SharePoint tools

Scroll to Top