What PnP PowerShell is
PnP PowerShell is an open-source, community-supported PowerShell module with more than 700 cmdlets for Microsoft 365, including SharePoint Online. To use it you install the module in PowerShell 7.4 or later, register your own Entra ID application, and connect to a site with Connect-PnPOnline.
Microsoft's own overview describes it as "a .NET 8.0 based PowerShell Module providing over 700 cmdlets that work with Microsoft 365 environments such as SharePoint Online, Microsoft Teams, Microsoft Project, Security & Compliance, Microsoft Entra ID, and more." The project's repository now puts the count at over 900. It runs on Windows, Linux and macOS.
Two things are worth knowing before you rely on it:
- It is a community project. Microsoft's overview says: "It is not a Microsoft-provided module so there's no SLA or direct support for this open-source component from Microsoft." Problems are reported on the project's issues list in GitHub.
- The current module is for SharePoint Online. The project's README says the cross-platform version "will only support SharePoint Online". The original Windows-only cmdlets, which supported SharePoint 2013, 2016 and 2019 on-premises, are a separate, older module.
Getting started has three steps, and the rest of this page follows them:
- Install the PnP.PowerShell module.
- Register your own Entra ID application.
- Connect and sign in.
PnP PowerShell and the SharePoint Online Management Shell
SharePoint administrators usually meet two modules. They are separate, with separate sign-in commands.
| PnP PowerShell | SharePoint Online Management Shell | |
|---|---|---|
| Module name | PnP.PowerShell | Microsoft.Online.SharePoint.PowerShell |
| Published by | The open-source PnP community | Microsoft |
| Support | Community, through GitHub issues | Microsoft |
| Sign-in command | Connect-PnPOnline | Connect-SPOService |
| What you connect to | A site, such as https://contoso.sharepoint.com/sites/projects | The SharePoint admin center, https://contoso-admin.sharepoint.com |
| PowerShell version | PowerShell 7.4.0 or later | Windows PowerShell 5, or PowerShell 7 with -UseWindowsPowerShell |
| Operating systems | Windows, Linux and macOS | Windows |
| Cmdlet names | Get-PnPList, Get-PnPListItem, Get-PnPFile | Get-SPOSite, Set-SPOSite, Set-SPOTenant |
For the Microsoft module, see Connect-SPOService: connect to SharePoint Online with PowerShell.
Step 1: Install PnP PowerShell
The installation page states the requirement in one line: "You need PowerShell 7.4.0 or later to use PnP PowerShell." Check your version with $PSVersionTable.PSVersion, then run the install command in a PowerShell 7 window.
| Task | Command |
|---|---|
| Install the latest stable release | Install-Module PnP.PowerShell |
| Update to the latest stable release | Update-Module PnP.PowerShell |
| Install the latest nightly build | Install-Module PnP.PowerShell -AllowPrerelease |
| Update to the latest nightly build | Update-Module PnP.PowerShell -AllowPrerelease -Force |
| Remove every installed version | Uninstall-Module PnP.PowerShell -AllVersions |
| Run it in a Docker container | docker run -it m365pnp/powershell |
Two notes from the project's README:
- Windows PowerShell 5.1 and the ISE. The README gives
Install-Module PnP.PowerShell -RequiredVersion 1.12.0 -Forcefor people still on PowerShell 5.1 or the ISE. That pins an old release, so the steps on this page assume PowerShell 7.4. - The version 4 preview. It is built on .NET 10 and needs PowerShell 7.6 or later. The stable release needs PowerShell 7.4.0 and is built on .NET 8.0.
Step 2: Register your own Entra ID application
PnP PowerShell signs in through an application registered in your own Microsoft Entra ID tenant. The registration guide says: "It has always been a recommended practice to register your own Entra ID Application to use with PnP PowerShell. As of September 9th, 2024, this has become mandatory step." On that date the shared, multi-tenant PnP Management Shell Entra ID app was deleted, which is why older scripts that connected without a client ID stopped working.
Register with one cmdlet
For interactive sign-in, run this once:
Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "PnP.PowerShell" -Tenant contoso.onmicrosoft.com
After the app is registered you are asked to give consent for it. Keep the application (client) ID, because every connection uses it.
The person running the cmdlet needs at least the Application Developer role or the Global Administrator role. The guide says the first "should be enough to create the application registration in Entra ID", and that Global Administrator permissions "might be needed after this to set the desired permissions on the application registration."
By default the cmdlet adds a limited set of permission scopes. To choose your own, use the -GraphDelegatePermissions, -SharePointDelegatePermissions, -GraphApplicationPermissions and -SharePointApplicationPermissions parameters.
Register by hand in the Entra admin center
The guide also documents the manual route. The settings that matter are:
| Setting | Value |
|---|---|
| Name | The guide recommends PnP.PowerShell, so the name matches the module |
| Platform | Mobile and desktop applications |
| Redirect URI | http://localhost - the guide stresses "this is http and NOT https" |
Extra redirect URI for -OSLogin | ms-appx-web://microsoft.aad.brokerplugin/{client_id} |
| API permissions | Delegated SharePoint permissions, for example AllSites.Read under AllSites |
| Consent | Grant admin consent for your organization. A greyed-out button means your account lacks the rights to consent |
The guide explains delegated permissions this way: "Delegated Permissions means that adding a permission level here does not mean that anyone gets those permissions." A person who signs in through the app can only do what their own SharePoint permissions allow.
Step 3: Connect with Connect-PnPOnline
Connect to the site you want to work on, with the client ID from Step 2:
Connect-PnPOnline -Url "https://contoso.sharepoint.com/sites/projects" -Interactive -ClientId <client id>
A sign-in window opens and you step through multi-factor authentication if your account uses it. Interactive is the default sign-in method. Run Get-PnPWeb afterward to confirm which site you are connected to.
Sign-in methods
| Method | Parameters | What the documentation says |
|---|---|---|
| Interactive | -Interactive -ClientId <client id> | Shows a popup window to "authenticate and step through the multi-factor authentication flow" |
| Device login | -DeviceLogin -ClientId <client id> | Gives you a code to enter at microsoft.com/devicelogin on any device, including any multi-factor step |
| Operating system login | -OSLogin -ClientId <client id> | Uses Web Account Manager, with Windows Hello, conditional access policies and FIDO keys. Needs the extra redirect URI from Step 2 |
| User name and password | -ClientId <client id> -Credentials (Get-Credential) | "It will not work with multi factor authentication. Therefore this method is less recommended." |
| Certificate file | -ClientId <client id> -Tenant contoso.onmicrosoft.com -CertificatePath <path to .pfx> | App-only sign-in with no person present |
| Certificate thumbprint | -ClientId <client id> -Tenant contoso.onmicrosoft.com -Thumbprint <thumbprint> | App-only, using a certificate imported into the Windows Certificate Store |
| Managed identity | -ManagedIdentity | For Azure Functions, Azure Automation runbooks and Azure Cloud Shell |
Save the client ID so you can leave it out
Typing -ClientId on every connection gets old. The documentation gives two ways to store it.
An environment variable. Name it ENTRAID_APP_ID, ENTRAID_CLIENT_ID or AZURE_CLIENT_ID; they are used in that order. On Windows:
[System.Environment]::SetEnvironmentVariable('ENTRAID_CLIENT_ID', '<client id>', [EnvironmentVariableTarget]::User)
A client ID for each tenant. Useful when you work in more than one tenant:
Set-PnPManagedAppId -Url https://contoso.sharepoint.com -AppId <client id>
This adds an entry to Windows Credential Manager, the macOS keychain or the Linux Secret Service, and Connect-PnPOnline -Url https://contoso.sharepoint.com -Interactive then picks the right client ID for the address. It is available in versions newer than 2.12.0. Add -Verbose to Connect-PnPOnline to see which client ID is used.
Tenant-wide cmdlets and the admin site
Cmdlets that work across the tenant, such as Get-PnPTenantSite, need "Access to the SharePoint Tenant Administration site", which means a SharePoint Administrator account. You do not have to connect to the admin address yourself: when -TenantAdminUrl is left out, the cmdlets "assume to connect automatically to" https://<tenant>-admin.sharepoint.com "where appropriate".
Work with two sites at once
-ReturnConnection returns a connection object and leaves your current connection alone. Pass it to other cmdlets with -Connection:
$archive = Connect-PnPOnline -Url "https://contoso.sharepoint.com/sites/archive" -Interactive -ClientId <client id> -ReturnConnection
Get-PnPList -Connection $archive
When you finish, Disconnect-PnPOnline disconnects the current connection and clears its token cache.
Connect without a person signing in
Scheduled scripts use app-only sign-in with a certificate. The authentication guide is direct about it: "Your application registration needs to use a public/private key pair certificate to authenticate. A client secret is not supported." The public key (.cer) goes into the app registration and the private key (.pfx) is used to connect.
Register-PnPEntraIDApp creates the app registration and the certificate together:
$result = Register-PnPEntraIDApp -ApplicationName "PnP.PowerShell" -Tenant contoso.onmicrosoft.com -OutPath c:\mycertificates -DeviceLogin
$result
The output shows the client ID. The cmdlet saves PnP.PowerShell.cer and PnP.PowerShell.pfx to the -OutPath folder, returns the private key certificate in base64 encoding, and shows a URL where an administrator gives consent.
Then connect with the certificate file:
Connect-PnPOnline contoso.sharepoint.com -ClientId <client id> -Tenant contoso.onmicrosoft.com -CertificatePath c:\mycertificates\PnP.PowerShell.pfx
If the .pfx has a password, add -CertificatePassword with a secure string. To use a certificate from the Windows Certificate Store, import the .pfx into Personal > Certificates and connect with -Thumbprint in place of -CertificatePath.
The cmdlets SharePoint admins use most
Each description below is taken from the cmdlet's own documentation page. Connect first; every cmdlet works on the site you connected to unless the table says otherwise.
Sites
| Cmdlet | What it does | Example |
|---|---|---|
Get-PnPTenantSite | Retrieves site collection information. With no parameters it returns all site collections except OneDrive sites. Needs SharePoint administrator access | Get-PnPTenantSite |
Get-PnPSite | Returns the current site collection | Get-PnPSite |
Get-PnPWeb | Returns the current web | Get-PnPWeb |
New-PnPSite | Creates a communication site, a Microsoft 365 group-connected team site, or a modern team site with no group | New-PnPSite -Type CommunicationSite -Title Contoso -Url https://contoso.sharepoint.com/sites/contoso |
Lists and items
| Cmdlet | What it does | Example |
|---|---|---|
Get-PnPList | Returns the lists in the current web | Get-PnPList |
New-PnPList | Creates a new list | New-PnPList -Title Announcements -Template Announcements |
Get-PnPListItem | Retrieves list items | Get-PnPListItem -List Tasks |
Add-PnPListItem | Adds an item to a list | Add-PnPListItem -List "Demo List" -Values @{"Title" = "Test Title"; "Category"="Test Category"} |
Set-PnPListItem | Updates a list item | Set-PnPListItem -List "Demo List" -Identity 1 -Values @{"Title" = "Test Title"; "Category"="Test Category"} |
Files and folders
| Cmdlet | What it does | Example |
|---|---|---|
Get-PnPFolderItem | Lists the files and subfolders in a folder. For a library with more than 5,000 items, use its -List parameter | Get-PnPFolderItem |
Get-PnPFile | Downloads a file. The example saves it to the current folder | Get-PnPFile -Url "/sites/project/Shared Documents/Document.docx" |
Add-PnPFile | Uploads a local file to a folder | Add-PnPFile -Path c:\temp\company.master -Folder "_catalogs/masterpage" |
Get-PnPFileVersion | Retrieves the previous versions of a file, without the current version | Get-PnPFileVersion -Url Documents/MyDocument.docx |
Recycle bin
| Cmdlet | What it does | Example |
|---|---|---|
Get-PnPRecycleBinItem | Returns items from the recycle bin of the site you connected to. With no parameters, the first-stage recycle bin | Get-PnPRecycleBinItem |
Restore-PnPRecycleBinItem | Restores a recycle bin item to its original location, after asking you to confirm | Restore-PnPRecycleBinItem -Identity 72e4d749-d750-4989-b727-523d6726e442 |
People and permissions
| Cmdlet | What it does | Example |
|---|---|---|
Get-PnPSiteCollectionAdmin | Returns the current site collection administrators | Get-PnPSiteCollectionAdmin |
Add-PnPSiteCollectionAdmin | Adds one or more site collection administrators, keeping the existing ones | Add-PnPSiteCollectionAdmin -Owners "user@contoso.onmicrosoft.com" |
Get-PnPGroup | Returns one SharePoint group or all SharePoint groups in the site | Get-PnPGroup |
Get-PnPGroupMember | Retrieves the members of a SharePoint group | Get-PnPGroupMember -Group "Marketing Site Members" |
Site templates
| Cmdlet | What it does | Example |
|---|---|---|
Get-PnPSiteTemplate | Generates a provisioning site template from a web | Get-PnPSiteTemplate -Out template.pnp |
Invoke-PnPSiteTemplate | Applies a site template to a web | Invoke-PnPSiteTemplate -Path template.xml -Url https://contoso.sharepoint.com/sites/sitename |
Two reports on this site are built from these cmdlets: how to check the size of SharePoint storage and finding SharePoint files not modified in years. When the second report shows libraries full of files nobody has touched, Squirrel archives them by last-modified age, site, library, folder or file type into your own Azure Blob Storage and leaves a stub so users can still open them.
Permissions that catch people out
Connecting successfully does not mean every cmdlet will run. Three requirements are written into the cmdlet documentation:
Get-PnPRecycleBinItemneeds a site collection administrator. Its page says: "SharePoint: Site Collection Administrator. SharePoint Tenant Admin alone is not enough". A SharePoint Administrator who is not an admin of the site connects to the tenant admin address and usesGet-PnPTenantRecycleBinItem. SharePoint site collection administrator explains how to add yourself.Add-PnPSiteCollectionAdminneeds you to be a site collection admin already. Its page says: "You must be a Site Collection Admin to run this command." A SharePoint Administrator who is not one usesSet-PnPTenantSite -Owners.New-PnPSiteneeds the right to create sites. With a signed-in user it requires "the SharePoint Administrator or Global Administrator role unless self service site creation is enabled."
The permissions on the app registration matter as well. A person who signs in through the app is limited by both the app's delegated permissions and their own SharePoint permissions.
Frequently asked questions
Is PnP PowerShell a Microsoft product?
It is an open-source library provided and supported by the community. Microsoft documents it and states that it "is not a Microsoft-provided module so there's no SLA or direct support for this open-source component from Microsoft." Issues are reported on GitHub.
Which version of PowerShell does PnP PowerShell need?
PowerShell 7.4.0 or later for the current stable release, which is built on .NET 8.0. The version 4 preview needs PowerShell 7.6 or later.
How do I install PnP PowerShell?
Open PowerShell 7 and run Install-Module PnP.PowerShell. To update it later, run Update-Module PnP.PowerShell.
Why does Connect-PnPOnline need a client ID?
On September 9th, 2024 the shared PnP Management Shell Entra ID app was deleted. Since then, interactive sign-in works only with the client ID of an Entra ID application registered in your own tenant. Register one with Register-PnPEntraIDAppForInteractiveLogin, then pass its ID with -ClientId or store it in the ENTRAID_CLIENT_ID environment variable.
Does PnP PowerShell work with multi-factor authentication?
Yes. -Interactive and -DeviceLogin both take you through the multi-factor step. Signing in with -Credentials does not work with multi-factor authentication.
Does PnP PowerShell run on a Mac or on Linux?
Yes. The module is cross-platform and runs on Windows, Linux and macOS, and there is a Docker image, m365pnp/powershell.
Does PnP PowerShell work with SharePoint Server?
The current module supports SharePoint Online. The original Windows PowerShell cmdlets supported SharePoint 2013, 2016 and 2019 on-premises and are a separate, older module.
What is the difference between PnP PowerShell and the SharePoint Online Management Shell?
The SharePoint Online Management Shell is Microsoft's module. You connect it to the SharePoint admin center with Connect-SPOService. PnP PowerShell is the community module. You connect it to a site with Connect-PnPOnline, and it has cmdlets for lists, items, files, the recycle bin and site templates.
How do I run PnP PowerShell in a scheduled script?
Use app-only sign-in with a certificate. Register-PnPEntraIDApp creates the app registration and the certificate files, and Connect-PnPOnline takes -ClientId, -Tenant and -CertificatePath or -Thumbprint. In Azure Automation or Azure Functions, -ManagedIdentity is the alternative.
Related reading
- Connect-SPOService: connect to SharePoint Online with PowerShell - the Microsoft module, its admin URL and sign-in options.
- SharePoint Online PowerShell - common commands for sites and storage.
- How to use SharePoint PowerShell - getting started with the SharePoint Online Management Shell.
- How to check the size of SharePoint storage - a storage report built with Get-PnPTenantSite.
- Find SharePoint files not modified in years - an age report built with PnP PowerShell.
- SharePoint site collection administrator: add, remove and find - the role several PnP cmdlets require.
- SharePoint recycle bin - the two stages and how long items are kept.
- SharePoint site templates - what a site template is and how to reuse a site design.
- SharePoint admin center - the URL, who can sign in and what each section does.
- How to download files and folders from SharePoint - the steps, the size and zip limits, and why the Download button is sometimes missing.
Mark Smith co-founded SmiKar Software in 2015 and has spent the past decade helping organisations solve Microsoft 365 data management challenges. He works with the SmiKar team to build solutions for SharePoint archiving, storage optimisation, governance and compliance, supporting customers from growing businesses through to Fortune 500 enterprises.
More about SmiKar


