How to Install the PnP PowerShell Module for SharePoint Online?
The PnP PowerShell module has become an indispensable tool for many SharePoint administrators and developers. This open-source module, created by Microsoft’s Patterns and Practices (PnP) initiative, provides a robust set of commands for managing SharePoint Online and SharePoint Server through PowerShell.
In this post, I will provide an overview of the PnP PowerShell module, discuss how to install and update it, demonstrate some key commands and capabilities, and share some of the common tasks to manage your SharePoint environment. Whether you are new to the PnP PowerShell module or looking to get more out of it, this post will help take your skills to the next level. By the end, you’ll have the module installed and connected to SharePoint Online using an authenticated session for executing commands.
Table of contents
What is PnP PowerShell?
The new PnP PowerShell module PnP.PowerShell is a cross-platform, .net framework-based PowerShell product that can run on any operating system that supports .net core, like Windows, Linux, macOS, etc., and provides 500+ cmdlets to work with Microsoft 365 environment (No support for On-Premises server products, As a side note!) cloud products like SharePoint Online, Microsoft Teams, Microsoft Planner, Security & Compliance, Azure Active Directory, and more.
If you are administering Microsoft SharePoint, you know that PnP PowerShell is an essential tool for managing your environment. It’s an open-source component and community-provided library with active community members providing support, so there won’t be any SLA or direct support from Microsoft. This article will show you how to install the PnP PowerShell module for SharePoint Online.
Install the PnP PowerShell Module: Step-by-Step
Managing SharePoint Online environments often requires executing repetitive administrative tasks – like creating sites, setting permissions, and configuring libraries. Carrying out these tasks manually through the SharePoint admin center can be time-consuming. That’s where the Patterns and Practices (PnP) PowerShell module comes into play.
To install the new PnP PowerShell module, You have to follow these steps:
- Uninstall the Legacy SharePointPnPPowerShellOnline Module, if already installed.
- Install the New PnP PowerShell Module.
- Register Azure AD Application and Grant Access to the tenant.
Let’s get started! Open the Windows PowerShell console as an Administrator and execute these steps to install PnP.PowerShell module.
Step 1: Uninstall the Legacy SharePointPnPPowerShellOnline Module
Check if the classic PnP PowerShell module is installed with the below command:
Get-Module SharePointPnPPowerShellOnline -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending
This returns the Name and version of legacy PnP PowerShell installed on the machine (If any). Uninstall Any previous PnP PowerShell Modules for SharePoint Online installed:
Uninstall-Module SharePointPnPPowerShellOnline -Force -AllVersions
Step 2: Install the New PnP PowerShell Module
How do I install a new PowerShell module? To install the new PnP PowerShell module, use:
Install-Module PnP.PowerShell
This will download and install the PnP PowerShell module from the PowerShell Gallery. How to install PnP PowerShell offline? If needed, You can also use setup files from GitHub, Download the PnP PowerShell Offline Installation package, and install it with the following:
Install-Package C:\Path\File.nupkg
Step 3: Register a new Azure AD Application and Grant Access to the tenant
Register-PnPManagementShellAccess
The final step is granting the tenant access to the PnP Management Shell Multi-Tenant Azure AD Application. On executing the above cmdlet, you’ll be prompted to log in and provide consent for your tenant. You must log in with Global Admin (or Tenant Administrator) permissions and complete this step.
In case you are not a global admin, use: Register-PnPManagementShellAccess -ShowConsentUrl and share the URL you get from this cmdlet with the Tenant Admin, and they can complete this consent step from the URL you share.
Finally, You can verify the installation by getting a list of PnP PowerShell commands:
Get-Command -Module PnP.Powershell
Connect to SharePoint Online site using PnP PowerShell
How do I use PnP PowerShell in SharePoint Online? Once you are done with the above steps, You can connect to SharePoint Online through PnP PowerShell scripts with username and password with the following commands:
#Connect to PnP Online
Connect-PnPOnline -Url "https://Crescent.sharepoint.com/sites/Marketing/" -Credential (Get-Credential)
#Get All Lists
Get-PnPList
Connect-PnPOnline using MFA
To connect to SharePoint Online using PnP PowerShell MFA (Multifactor authentication): Use the “-Interactive” switch instead of “Credentials” if your account is MFA enabled. Behind the scenes, each cmdlet executes a client-side object model code to achieve functions.
#Connect to SharePoint site
Connect-PnPOnline -Url "https://Crescent.sharepoint.com/sites/Marketing/" -Interactive
#Get All Lists
Get-PnPList
PnP PowerShell to Connect to OneDrive for Business
Microsoft OneDrive for Business – The cloud-based storage and file-sharing part of the Office 365 suite can be managed with PowerShell, too. To access the OneDrive for Business site from PowerShell, you will need to first connect to the OneDrive site by running the following cmdlet: Connect-PnPOnline. Once you are authenticated, you can then run any available cmdlets against your OneDrive for Business site just as you would any other SharePoint Online site. E.g., let’s connect to the OneDrive site and create a new folder:
#Parameters
$OneDriveSiteURL = "https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com"
$FolderName = "Archives"
Try {
#PowerShell to Connect to OneDrive for Business
Connect-PnPOnline -Url $OneDriveSiteURL -Interactive
#ensure folder in SharePoint Online using powershell
Resolve-PnPFolder -SiteRelativePath "Documents/$FolderName"
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
Managing PnP PowerShell Module
Let’s see how to update it, find the installed module version, and uninstall the module:
Update PnP PowerShell for SharePoint Online
How do I update PnP PowerShell? To update the PnP PowerShell, run the following:
Update-Module -Name "PnP.PowerShell"
This will download and install the latest version of PnP PowerShell module on your local machine.
What version of PnP PowerShell do I have?
To check the installed version of PnP PowerShell in your system, use:
Get-InstalledModule -Name "PnP.PowerShell"
Uninstall the PnP PowerShell Module
If you would like to remove the PnP PowerShell, you can run the following:
Uninstall-Module -Name "PnP.PowerShell"
Can I have both the New PnP PowerShell and the Classic PnP Modules?
If you want to use the PnP PowerShell module for SharePoint Server (On-Premises), You can install it along with Pnp.PowerShell module as:
Install-Module -Name SharePointPnPPowerShell2019 -AllowClobber
This script installs the SharePointPnPPowerShell2019 module and makes cmdlets available from this module. You can use “Import-Module SharePointPnPPowerShell2019” on the first line to instruct your script to load and use Cmdlets from this specific module. As a side note, the old SharePointPnPPowerShellOnline module is archived and no longer updated.
At times, You may need to use the CSOM PowerShell scripts with the combination of PnP PowerShell cmdlets, as we don’t have PnP PowerShell cmdlets for each and everything in SharePoint Online: How to Connect to SharePoint online using CSOM PowerShell?
Most Common PnP PowerShell Cmdlets for SharePoint Online
Here are some of the most common PnP PowerShell cmdlets for SharePoint Online from the PnP.PowerShell module.
Conclusion
And that wraps up this guide on installing and configuring the incredibly useful PnP PowerShell module for SharePoint Online! As you’ve seen, getting set up with PnP PowerShell is quick and easy with just a few PowerShell commands.
Now that you have the module installed, you have access to a vast suite of commands for efficiently administering your SharePoint Online environments. From creating sites, lists, libraries, and columns to applying themes, managing permissions, and more – the possibilities are endless with PnP PowerShell.
Be sure to check out the documentation on the available cmdlets to leverage its capabilities fully. As SharePoint Online continues to evolve, so will the PnP PowerShell module, with new features added regularly.
I hope you found this guide helpful. The PnP PowerShell module can massively boost your productivity as a SharePoint admin or developer. Automating tasks allows you to focus on more strategic initiatives rather than heavy manual configuration.
Use: Get-PnPField | Select Title, TypeDisplayName, InternalName
More info: Get Site Columns in SharePoint Online using PowerShell
To get IDs of all SharePoint Online document libraries, use: Get-PnPList | Where-Object {$_.BaseType -eq “DocumentLibrary”}
More info: Get All Document Libraries in SharePoint Online
Use the Add-PnPNavigationNode cmdlet to create a top navigation link to the SharePoint Online site.
More info: Add Top Navigation Link in SharePoint Online using PowerShell
The SharePoint Online Management Shell is a PowerShell Module that helps administrators to manage SharePoint Online sites. Just install the PowerShell Module “Microsoft.Online.SharePoint.PowerShell”, connect to SharePoint Online with Connect-SPOService, and then you can start using any available cmdlets.
More info: Connect to SharePoint Online from PowerShell
If you want to install the legacy SharePointPnPPowerShellOnline module for backward compatibility or to manage SharePoint On-premises versions, use: “Install-Module SharePointPnPPowerShellOnline”
More info: How to Connect to SharePoint Online using PnP PowerShell?
Trying to install but is not working. Run as administrator, ran “Install-Module PnP.PowerShell”, then ran ‘Register-PNPManagementShellAccess” but this is not recognized. Tried uninstalling any current versions, again, get an error stating no match was found. Tried “Install-Package C:\Path\File.nupkg”, no match found. At a loss here.
Why even installing the PNP package, when I try to find any cmdlet, none appears? Even the ones in this guide when I execute then, an Not recognized cmdlet error is shown.
Can you try reopening the PowerShell console or ISE?
Already did but didn’t worked. Already updated the PS and tried even in W11 and WS 2019.
Hi Salaudeen Rajack, Thank you so much for providing the PnP scripts… it is the only resource I can relay to solve my PnP queries(almost all) thanks again.
Well, some time ago I got some issue with my machine that left me in the situation of re-install the window anyway. Now, I am trying to install my PnP module again and it’s not allowing me to do so, showing me an error
“Install-Package: No match was found for the specified search criteria and module name ‘PnP.PowerShell’. Try Get-PSRepository to see all available registered module repositories.”
on running Get-PSRepository command getting “Unable to find module repositories.”
tried so many ways after that but no luck can you kindly help in this regard? Would be highly grateful. Thanks in anticipation.
Is it possible to deploy PnP.PowerShell Version = 1.12.0 from Intune? I tried but i guess in need admin rights for that and Run this script using the logged on credentials : No doesn’t help.
Any other solution?
Thank you for this post. When I try the 3rd step, I get this
“Register-PnPManagementShellAccess : The ‘Register-PnPManagementShellAccess’ command was found in the module
‘PnP.PowerShell’, but the module could not be loaded. For more information, run ‘Import-Module PnP.PowerShell’.
At line:1 char:1
+ Register-PnPManagementShellAccess
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Register-PnPManagementShellAccess:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule”
I thought it would be a good idea to Import-Module -Name “PnP.PowerShell”
that yields:
Import-Module : Could not load file or assembly ‘System.Management.Automation, Version=7.2.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.
At line:1 char:1
+ Import-Module -Name “PnP.PowerShell”
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
Is it mandatory to register an Azure AD Application and Grant Access to the tenant? Or being a sharepoint admin and have installed PnP Powershell is enough to run some of the scripts?
Yes, That’s mandatory! Because of the New PnP.PowerShell module uses the Application ID from Azure AD. If you are not a Tenant Admin, You can provide the Consent URL to the Admin and get the rights granted.
We are getting the authorisation request each time even though the Tenant Admin has authorised the module across the tenant. Any ideas what we’ve missed?
Thanks
i am getting error when trying to do offline installation install-package Install-Package C:\install\pnp.powershell.1.12.0.nupkg -Verbose
Install-Package : Package ‘PnP.PowerShell’ failed to install.
At line:1 char:1
+ Install-Package C:\install\pnp.powershell.1.12.0.nupkg -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (PnP.PowerShell:String) [Install-Package], Exception
+ FullyQualifiedErrorId : PackageFailedInstallOrDownload,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
The command you have to get version and to remove are the same.
Fixed it! Thanks.
The version 1.11.0 of PnP.Powershell is extremely buggy and broken. It does not even match documentation.
Ex: Remove-PnPWeb -Identity (Most used to be able to use -URL, which was removed. Documentation for -Identity parameter states one can use the name not the GUID ID for it, but it will never find it)
Been trying to figure out a way to downgrade to 1.10.0 to no avail.
Thanks very much for all you do, your site has saved me many times over. I am wondering if you have ever come across this error when registering PnP PowerShell though. “Authentication failed.
You did not consent for the PnP Management Shell Application for use by PnP PowerShell. Feel free to close this browser window.
Error details: error invalid_client error_description:AADSTS650052: The app is trying to access a service ‘00000007-0000-0000-c000-000000000000′(Dataverse) that your organization ‘0a6e4b53-5fe9-41b3-b7e3-434ff1783940’ lacks a service principal for. Contact your IT Admin to review the configuration of your service subscriptions or consent to the application in order to create the required service principal. ” I have been searching for hours with no luck.
Pingback: How to Connect to SharePoint Online using PnP PowerShell? - SharePoint Diary
Thank you so much for posting this!!! I was finally able to get my SharePoint 2016 on-prem server to connect to SharePoint Online! Now I can run scripts to sync data between them where needed!