Installing PnP PowerShell 2.x On Windows 10

Introduction

For installing PnP PowerShell 2.x on your windows 10 machine, you must have PowerShell 7 and above version. Let me give you a little background. I need PowerShell 7 (in fact, I was forced :)) to work with the latest PnP PowerShell 2.x modules as it has some new enhancements such as setting up classification at document library, retrieving service principal registrations for an Azure AD App, and much more. Please refer to the change log in the references section for complete updates. The PnP PowerShell 2.x modules require PowerShell 7, which won't work on version PowerShell 5.1 and below. In this article, we will go through the following.

  • Installing PowerShell 7
  • Installing PnP PowerShell 2.1.0 (the stable version as of writing this document)

Also, the latest development on PnP PowerShell will be continuing on PowerShell 7. It's time to upgrade from PowerShell 5 to PowerShell 7, a cross-platform tool. More about the PowerShell 7 can be learned from the references section.

Steps to Install PowerShell 7.x

Let's go to the steps needed to install PowerShell 7. Note that the steps are documented based on Windows 10 OS. Similar steps should work for other OS too.

Step 1

Go to the below link

Installing PowerShell on Windows

Step 2

Install the MSI package by going to the "Installing MSI Package" section. You can also go to the below direct link to download the MSI package.

Installing PnP PowerShell 2.x on Windows 10

Download the MSI package

Step 3

The installation is simple. It is self-explanatory, and follow the prompts to install PowerShell 7.

Step 4

Validate the installation by going to windows start programs and searching for PowerShell.

Once the installation is successful, check for PowerShell 7 in your start programs.

Installing PnP PowerShell 2.x on Windows 10

The above steps conclude the installation of PowerShell 7 on your Windows 10 machine.

Installing PnP PowerShell 2.x

Step 1

Open PowerShell 7, and you may have noticed that there is no ISE for this version 7, and everything should run via the console.

Step 2

Get the installed PnP PowerShell version by entering the below command

Get-Module "PnP.PowerShell" -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending

Installing PnP PowerShell 2.x on Windows 10

Step 3

In this case, I already have installed 1.12.0. If no previous version of PowerShell is installed, you will get the blank output.

Step 4

Install the PnP PowerShell 2.x version by running the below command.

Install-Module -Name "PnP.PowerShell"

If your environment is restricted, you might end up with the following output saying that unable to resolve package source https://www.PowerShellGallery.com/api/v2

Installing PnP PowerShell 2.x on Windows 10

In this case, it is required to install the PnP PowerShell in offline mode.

Step 5

Go to the PowerShell Gallery by clicking on https://www.PowerShellGallery.com and search for PnP PowerShell.

Installing PnP PowerShell 2.x on Windows 10

Step 6

Look for the icon and the latest update date.

Installing PnP PowerShell 2.x on Windows 10

Step 7

Look for manual download and click on the 'Download Raw nupkg file'.

Installing PnP PowerShell 2.x on Windows 10

Step 8

I have downloaded this file to c:\install as I have set up this folder as my local repository. Please refer to the references section on how to set up the local repository.

Step 9

Install the PnP PowerShell from your local repository by running the below command.

Install-Module -Name "PnP.PowerShell" -Repository local -Force

Note: If you want to install both PnP PowerShell 1.x and 2.x, then apply the -force parameter. I tried installing the PnP PowerShell 2.x version, and initially, without -force, it gave me the following error. It basically requests to run with the -force parameter.

PS C:\Users\vayina1> Install-Module -Name "PnP.PowerShell" -Repository local
WARNING: Version '1.12.0' of module 'PnP.PowerShell' is already installed at 'C:\Program Files\WindowsPowerShell\Modules\PnP.PowerShell\1.12.0'. To install version '2.1.1', run Install-Module and add the -Force parameter; this command will install version '2.1.1' side-by-side with version '1.12.0'.

Validation

Run the following command to get the available installed PnP PowerShell Versions.

Get-Module "PnP.PowerShell" -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending

Installing PnP PowerShell 2.x on Windows 10

You may also check the following commands to connect the site and retrieve lists. For instance, I have run the following commands to retrieve the list information. 

#Connecting to SPO site using PnP Latest Module
Connect-PnPonline -url "https://contoso.sharepoint.com/sites/TestContoso" -Interactive
#Getting the list information
Get-PnPList

Conclusion

Thus in this article, we have gone through how to install PowerShell 7 and set up the latest version of PnP PowerShell. 

References

  • https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.2
  • https://pnp.github.io/powershell/articles/installation.html
  • https://www.c-sharpcorner.com/blogs/how-to-install-powershell-modules-in-offline-mode
  • https://github.com/pnp/powershell/blob/dev/CHANGELOG.md


Similar Articles