Install PnP PowerShell for SharePoint Online | PnP PowerShell connect to SharePoint Online

Want to know how to work with PnP PowerShell SharePoint Online? In this tutorial, we will discuss how to install PnP PowerShell on Windows 10 machine, and then we will discuss how to connect to sharepoint online using pnp PowerShell.

How to install PnP PowerShell module for SharePoint? Based on your SharePoint Online environment, run any one of the below commands to install PnP PowerShell to work with SharePoint?

SharePoint Version Command to Install
SharePoint Online (New) Install-Module PnP.PowerShell
SharePoint Online (Legacy) Install-Module SharePointPnPPowerShellOnline
SharePoint Server 2019 Install-Module SharePointPnPPowerShell2019
SharePoint Server 2016 Install-Module SharePointPnPPowerShell2016
SharePoint Server 2013 Install-Module SharePointPnPPowerShell2013

We will see here, how to install pnp PowerShell.

Note: The SharePointPnPPowerShellOnline module is not maintained anymore, so we should use the newer version and that is PnP.PowerShell.

What is PnP PowerShell

PnP.PowerShell is a new cross-platform PowerShell module released that contains more than 600 cmdlets to work with various Microsoft 365 environments like SharePoint Online, Microsoft Power Automate or Flow, Microsoft Teams, Microsoft Planner, etc.

Install PnP.PowerShell

Now, let us see how to install PnP PowerShell.

All the cmdlets will work on PowerShell 7.x, but most of the cmdlets will work in PowerShell 5.x. If you want to check the current version, then you can run the below command:

$PSVersionTable

If you have the PowerShell 5.x, then better to upgrade to PowerShell 7.x.

For this, download the PowerShell-7.x.msi file and then run the .msi file.

install powershell 7
install PowerShell 7

Click on Next -> Next -> and then click on Install.

download PowerShell 7
download PowerShell 7

Once you click on Install, it will take some time to install and you can see the progress.

download and install PowerShell 7
Download and install PowerShell 7

Now, you can see the PowerShell 7 cmd prompt like below:

PowerShell 7
PowerShell 7

Now, let us see, how to install PnP PowerShell.

Step-1: If you have installed the SharePointPnPPowerShellOnline Module, then first uninstall this module by running the below command.

Uninstall-Module SharePointPnPPowerShellOnline -Force –AllVersions

Step-2: Now, it is time to install the new PnP.PowerShell module by running the below command.

Install-Module PnP.PowerShell
Install PnP PowerShell Module for SharePoint Online
Install PnP PowerShell Module for SharePoint Online

Step-3: Once the module is installed successfully, we need to run the below command to register Azure AD Application and Grant Access to the Office 365 tenant like below:

Register-PnPManagementShellAccess
Install PnP PowerShell Module
Install PnP PowerShell Module

Step-4: Now we can connect to any SharePoint Online site in that tenant by running the commands like below:

Connect-PnPOnline -Url "https://tsinfotechnologies.sharepoint.com/sites/Internal/" -UseWebLogin

Connect-PnPOnline -Url "https://tsinfotechnologies.sharepoint.com/sites/Internal/" -Credential (Get-Credential)

The below command you can use if you have multi-factor authentication (MFA) is enabled.

Connect-PnPOnline -Url "https://tsinfotechnologies.sharepoint.com/sites/Internal/" -Interactive

Step-5: Once you are connected you can run the below command to see if you are getting information from the SharePoint site.

Get-PnPList
How to Install the PnP PowerShell Module for SharePoint Online
How to Install the PnP PowerShell Module for SharePoint Online

Update PnP PowerShell

To update the PnP PowerShell module for SharePoint Online, run the below command:

Update-Module -Name "PnP.PowerShell"

Uninstall PnP PowerShell

To uninstall the PnP PowerShell module for SharePoint Online, run the below command:

Uninstall-Module -Name "PnP.PowerShell"

pnp.powershell vs sharepointpnppowershellonline

  • The main difference between pnp.powershell and sharepointpnppowershellonline is that, sharepointpnppowershellonline module works only in SharePoint Online where as pnp.powershell is a cross platform library.
  • By using pnp.powershell, we can work in Windows, Linux and MacOS. By using pnp.powershell, we can work with SharePoint Online, Microsoft Teams, Microsoft Planner and Microsoft Power Automate.

How to install PNP PowerShell in Windows 10 for SharePoint online

PnP stands for patterns and practices which contain various PowerShell commands as a library known as PnP Powershell which we can use to perform complex actions in SharePoint.

These commands internally use CSOM ( client-side object model) and we can use PnP PowerShell with SharePoint Online as well as SharePoint on-premises versions like SharePoint 2013, SharePoint 2016, and Sharepoint 2019.

Let us see, how to install pnp PowerShell.

If you are using Windows 10 OS, then we can easily install PnP PowerShell for SharePoint Online.

Open Windows PowerShell in administrator mode and run the below command:

Install-Module SharePointPnPPowerShellOnline
install pnp powershell for sharepoint online
PnP PowerShell SharePoint Online

Almost every month Microsoft releases new PNP PowerShell cmdlets and it is easier to update to the latest version of PnP Powershell.

To update PnP PowerShell, run the below command and it will install the latest version of PnP Powershell.

Update-Module SharePointPnPPowerShellOnline

To uninstall PnP PowerShell for SharePoint Online run the below command.

Uninstall-Module SharePointPnPPowerShellOnline

Install PnP PowerShell for SharePoint 2013

If you are working with SharePoint 2013 then you can run the below command to install PnP PowerShell which will work for SharePoint on-premises version 2013.

Install-Module SharePointPnPPowerShell2013

Update PnP PowerShell for SharePoint 2013:

Update-Module SharePointPnPPowerShell2013

Remove or Uninstall PnP PowerShell for SharePoint 2013:

Uninstall-Module SharePointPnPPowerShell2013

Install PnP PowerShell for SharePoint 2016

In the same way, if you want to install PnP PowerShell for SharePoint 2016 or to connect to SharePoint 2016 then run the below command:

Install-Module SharePointPnPPowerShell2016

Update PnP PowerShell for SharePoint 2016:

Update-Module SharePointPnPPowerShell2016

Remove or Uninstall PnP PowerShell for SharePoint 2016:

Uninstall-Module SharePointPnPPowerShell2016

Install PnP PowerShell for SharePoint 2019

SharePoint 2019 is the latest version of SharePoint on-premises. If you want to connect to SharePoint 2019 sites from your Windows 10 operating system, then run the below command.

Install-Module SharePointPnPPowerShell2019

If you want to update PnP PowerShell for SharePoint 2019 run the below command in Windows PowerShell:

Update-Module SharePointPnPPowerShell2019

Remove or Uninstall PnP PowerShell for SharePoint 2019:

Uninstall-Module SharePointPnPPowerShell2019

Check PnP PowerShell Version

Run the below command to check which version is installed in the system:

Get-Module SharePointPnPPowerShellOnline -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending
Check PnP PowerShell Version
Check pnp powershell version

Uninstall All Versions on PnP PowerShell

You can use the below command in PowerShell to uninstall all the versions of PnP PowerShell installed in the system.

Uninstall-Module SharePointPnPPowerShellOnline -AllVersions

Like in the above picture, it will install both versions of PnP PowerShell from my system.

Connect to SharePoint Online Site using PnP PowerShell

You can run the below command to connect to SharePoint Online sites from PnP Powershell.

Connect-PnPOnline –Url https://tsinfo.sharepoint.com/sites/SharePointSky –Credentials (Get-Credential)

If you are using multi Factor authentication then you can run the below command to connect to SharePoint online send from PnP PowerShell:

Connect-PnPOnline –Url https://tsinfo.sharepoint.com/sites/SharePointSky –UseWebLogin

Now, you can get all the lists from a SharePoint site by using the below PnP PowerShell command:

Get-PnPList

You can see the output like below:

pnp powershell get all lists
PnP PowerShell SharePoint Online

There are lots of PnP PowerShell commands are available, you can check in this URL.

Or you can also run the below cmdlets:

Get-Command -Module SharePointPnPPowerShell*

Download and Install PnP PowerShell from repository

Apart from running the commands online, we can also install PNP PowerShell from setup files that are available in the PnP PowerShell repository.

You can visit this URL and here you will be able to see .msi files that are available for SharePoint Online and SharePoint 2013/2016/2019.

install pnp powershell from msi package
install pnp powershell

You can also download the source code in zip file format.

Connect-PnPOnline : The ‘Connect-PnPOnline’ command was found in the module ‘SharePointPnPPowerShellOnline’

Let us see, how to resolve an error Connect-PnPOnline : The ‘Connect-PnPOnline’ command was found in the module ‘SharePointPnPPowerShellOnline’, ut the module could not be loaded. For more information, run Import-Module SharePointPnPPowerShellOnline.

The error comes when I run the below command to connect to the SharePoint Online site using PnP PowerShell cmdlets.

Connect-PnPOnline –Url https://onlysharepoint2013.sharepoint.com/sites/SharePointSky –Credentials (Get-Credential)

This is how the error looks like below:

Connect-PnPOnline The Connect-PnPOnline command was found in the module SharePointPnPPowerShellOnline
Connect-PnPOnline The Connect-PnPOnline command was found in the module SharePointPnPPowerShellOnline

Connect-PnPOnline : The ‘Connect-PnPOnline’ command was found in the module ‘SharePointPnPPowerShellOnline’

The error usually comes if there is a conflict with the PnP SharePoint version installed in the machine.

I installed Install-Module SharePointPnPPowerShellOnline in the same machine where I have SharePoint 2016 is installed.

I tried to reinstall Install-Module SharePointPnPPowerShellOnline and then when I run the command the issue got resolved.

Once you download the .msi file you can then install and use PnP PowerShell.

Here, we learned, what is PnP PowerShell? How to install and use PnP PowerShell for SharePoint Online or SharePoint 2013/2016/2019. I hope you got an idea on how to install PnP PowerShell and how to connect to sharepoint online using pnp PowerShell.

  • The commands are not working as expected.

    When I tried

    Connect-PnPOnline –Url https://xxx.sharepoint.com –Credentials (Get-Credential)

    It asked me to uninstall all previous versions of “SharePointPnPPowerShellOnline” and install “PnP.PowerShell” like below

    Uninstall-Module -Name SharePointPnPPowerShellOnline -AllVersions -Force
    Install-Module -Name PnP.PowerShell

    Then I again tried

    Connect-PnPOnline –Url https://xxx.sharepoint.com –Credentials (Get-Credential)

    Connect-PnPOnline : AADSTS65001: The user or administrator has not consented to use the application with ID ‘31359c7f-bd7e-475c-86db-fdb8c937548e’
    named ‘PnP Management Shell’. Send an interactive authorization request for this user and resource.

  • >