How to Install the PnP PowerShell Module for SharePoint Online?

The new PnP PowerShell module is a cross-platform product that can run on any operating system that supports .net core, like Windows, Linux, Mac, etc. and provides 500+ cmdlets to work with Microsoft 365 environment (No support for On-Premises server products, BTW!) cloud products like SharePoint Online, Microsoft Teams, Microsoft Planner, and Microsoft Flow. To install the new PnP PowerShell module, You have to follow these steps:

  1. Uninstall the Legacy SharePointPnPPowerShellOnline Module if installed.
  2. Install the New PnP PowerShell Module
  3. 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 in the order to install PnP.PowerShell module.

install pnp powershell sharepoint online

Step 1: Uninstall the Legacy SharePointPnPPowerShellOnline Module

Uninstall Any previous PnP PowerShell Modules for SharePoint Online installed.

Uninstall-Module SharePointPnPPowerShellOnline -Force –AllVersions

Step 2: Install the New PnP PowerShell Module

Install the new PnP PowerShell module using:

Install-Module PnP.PowerShell

Step 3: Register a new Azure AD Application and Grant Access to the tenant

Register-PnPManagementShellAccess

The final step is to grant access to the tenant for 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 got to login as a Global Admin and complete this step.

add permission to PnP Management Shell

Finally, You can verify the installation with:

Get-Command -Module PnP.Powershell

Connect SharePoint Online site using PnP PowerShell

Once you are done with the above steps, You can connect to SharePoint Online through PnP PowerShell as:

#Connect to PnP Online
Connect-PnPOnline -Url "https://crescentintranet.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: Use “-Interactive” switch instead of “Credentials” if your account is MFA enabled.

#Connect to PnP Online
Connect-PnPOnline -Url "https://crescentintranet.sharepoint.com/sites/Marketing/" -Interactive

#Get All Lists
Get-PnPList

Update PnP PowerShell for SharePoint Online

To update the PnP PowerShell, run:

Update-Module -Name "PnP.PowerShell"

Uninstall PnP PowerShell Module

If you would like to remove the PnP PowerShell, you can run:

Uninstall-Module -Name "PnP.PowerShell"

In case, You would like 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 installs the SharePointPnPPowerShell2019 module and makes cmdlets available from this module. You can use “Import-Module SharePointPnPPowerShell2019” at the first line to instruct your script to load and use Cmdlets from this specific module.

BTW, the old SharePointPnPPowerShellOnline module is archived and no longer updated.

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply