Never used PowerShell? Start here
This page gets you ready to run our read-only script from the content approval report page. Follow the sections in order. Skip any step you have already done.
What a PowerShell window is
A PowerShell window is a program where you type a command as text and press Enter. The computer runs the command and shows the result as text in the same window. You type or paste, and you read what comes back.
Working with an AI assistant
An AI chat app does not run commands on your computer. You do that part yourself:
- Copy a command from the chat.
- Paste it into the PowerShell window and press Enter.
- Select the text the window shows with the mouse, copy it (Ctrl+C on Windows, Cmd+C on Mac) and paste it back into the chat.
To get step by step help, paste the AI prompt from the script page into a new chat as your first message.
Never paste passwords, sign-in codes, tokens, client secrets or real customer data into the chat. Before you share a result, replace real site addresses and names with contoso.
Install PowerShell 7
Windows already has an older version called “Windows PowerShell 5.1”. Our script needs PowerShell 7, because PnP PowerShell needs PowerShell 7.4.0 or later.
On Windows, open “Terminal” or “Windows PowerShell” from the Start menu and run this command:
winget install --id Microsoft.PowerShell --source winget
The winget tool is included in Windows 11 as part of App Installer. As an alternative, download the MSI installer from the GitHub releases page linked on Install PowerShell on Windows (Microsoft Learn) (opens in a new tab) and double-click it.
On macOS, download the .pkg file from the releases page linked on Install PowerShell on macOS (Microsoft Learn) (opens in a new tab) and double-click it in Finder.
To start PowerShell 7 on Windows, open “PowerShell 7” from the Start menu or type the command below. On macOS, open the Terminal app and type the same command.
pwsh
Check that it worked:
$PSVersionTable.PSVersion
The number under Major should be 7, and the number under Minor should be 4 or higher. The PS C:…> prompt looks the same in PowerShell 7 and in Windows PowerShell 5.1, so this check is the proof. If pwsh is not recognized right after the install, close the window and open “PowerShell 7” from the Start menu.
Install PnP PowerShell
PnP PowerShell is a module. A module is an add-on that gives PowerShell extra commands, in this case commands for SharePoint. In the PowerShell 7 window run:
Install-Module PnP.PowerShell -Scope CurrentUser
This installs the module for your user only. When it succeeds, it usually prints nothing more and the prompt comes back without red text. You do not need admin rights on the computer. It may ask if you trust the PSGallery repository. Answer Y.
Get an app registration
Since 9 September 2024 PnP PowerShell requires your own Entra ID app registration. An app registration is an entry in Entra ID, the sign-in service behind Microsoft 365, that allows a tool to sign in as you. It has an Application (client) ID. The script asks for that ID.
If you are an admin: creating the app registration needs at least the Application Developer role. Granting the permissions may need a Global Administrator. Replace yourtenant.onmicrosoft.com with your own tenant name. It is usually the first part of your SharePoint address: for contoso.sharepoint.com it is contoso.onmicrosoft.com. If you are not sure, ask your administrator. Then run:
Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "PnP read-only checks" -Tenant yourtenant.onmicrosoft.com -SharePointDelegatePermissions "AllSites.Read"
The command opens a browser where you sign in. When it finishes, it shows the Application (client) ID next to AzureAppId/ClientId. Do not remove -SharePointDelegatePermissions “AllSites.Read” from the command. Without it, the command registers broad default permissions: SharePoint TermStore.ReadWrite.All, AllSites.FullControl and User.ReadWrite.All, and Graph Group.ReadWrite.All and User.ReadWrite.All. Our script only needs the delegated SharePoint permission AllSites.Read (tested by us on 2026-12-01). More details are on Register an Entra ID application (PnP PowerShell) (opens in a new tab).
If you are not an admin, send this to your Microsoft 365 administrator:
Please create an Entra ID app registration for PnP PowerShell interactive login with the delegated SharePoint permission AllSites.Read and admin consent, and send me its Application (client) ID.
Please create an Entra ID app registration for PnP PowerShell interactive login with the delegated SharePoint permission AllSites.Read and admin consent, and send me its Application (client) ID.
Save the script
Open the content approval report page and copy the script with the Copy button. Paste it into Notepad on Windows, or into TextEdit on Mac after choosing Format > Make Plain Text. Save it as Get-LibraryApprovalReport.ps1 in a folder such as Documentsscripts. Create the scripts folder first if it does not exist. Check that the file name ends with .ps1 and not .txt.
Run the script
In the PowerShell 7 window, go to the folder where you saved the script. This command works on Windows and Mac. If the folder is not found, tell the assistant where you saved the file:
cd $HOME/Documents/scripts
Then run the command below. Replace the example site address with your own, and replace the zeros with your Application (client) ID:
.Get-LibraryApprovalReport.ps1 -SiteUrls "https://contoso.sharepoint.com/sites/Quality" -ClientId "00000000-0000-0000-0000-000000000000"
SiteUrls accepts one site address or several, each in its own quotes with a comma between, for example “contoso.sharepoint.com/sites/Quality”,”contoso.sharepoint.com/sites/Projects” (opens in a new tab). Run it with an account that can see drafts, such as a site owner or a user with Approve Items permission. The script changes nothing. It saves a CSV file in the current folder named like library-approval-report-YYYYMMDD-HHMM.csv and shows a short summary in the window.
When something goes wrong
If the window shows red text, that is an error. Copy the error text into the chat and ask the assistant what it means.
Two checks to try first.
First, make sure you are in PowerShell 7 and not in Windows PowerShell 5.1. A new Terminal or PowerShell window can open Windows PowerShell 5.1. Run this and look for Major 7 and Minor 4 or higher. If you see 5, type pwsh and press Enter, then try again:
$PSVersionTable.PSVersion
Second, make sure you are in the folder where you saved the script. If you saved it in Documentsscripts, run:
cd $HOME/Documents/scripts
Then list the files and check that the name ends with .ps1 and not .ps1.txt:
dir
If the report runs but the numbers look too low, check the account you signed in with. Use an account that can see drafts, such as a site owner or a user with Approve Items permission. With a reader account, the counts can be lower than the real numbers.

