PnP PowerShell SharePoint Online – How to Connect

Want to know how to work with PnP PowerShell SharePoint Online? In this tutorial, we will discuss how to install PnP PowerShell in Windows 10 machine, and then we will discuss how to connect with SharePoint Online site using PnP PowerShell commands.

We will see here, how to install pnp powershell.

What is PnP PowerShell

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.

How to install PNP PowerShell in Windows 10 for SharePoint online

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 PowerShel for SharePoint 2013:

Uninstall-Module SharePointPnPPowerShell2013

How to install PnP PowerShell for SharePoint 2016

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 PowerShel 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 PowerShel 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 the 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 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.

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 connect with SharePoint Online sites.

>