Installing PnP PowerShell for SharePoint Online and Azure Cloud Shell

Installing PnP PowerShell for SharePoint Online and Azure Cloud Shell

Using PnP PowerShell in Azure Cloud Shell

SharePoint Patterns and Practices (PnP) contains a library of PowerShell commands (PnP PowerShell) that allows you to perform complex provisioning and artifact management actions towards SharePoint.

What is PnP?

It is a cross-platform PowerShell, and it is a .NET Core 3.1 / .NET Framework 4.6.1 based PowerShell Module providing over 600 cmdlets that work with Microsoft 365 environments such as SharePoint Online, Microsoft Teams, Microsoft Project, Security & Compliance, Azure Active Directory, and more.

Why do we need PnP PowerShell?

Microsoft has provided additional PnP PowerShell cmdlets to the SharePoint Online cmdlets. I believe the PnP PowerShell cmdlets are developer-focused and provide the means to manage artifacts in SharePoint, such as lists, views, fields, content types, and so on.

PnP PowerShell internally implements the Client-Side object model for its operations. This makes the operations adaptable. The same set of operations can be executed on any SharePoint environment. Using PnP PowerShell, a single line of code is used to access an object on SharePoint, wherein with the traditional Client-Side or Server-Side object model, multiple lines of code are required to access the objects. The code complexity reduces through this implementation.

It is recommended to use PowerShell 7.x, which can be installed by following these instructions (although most of the cmdlets should work under PowerShell 5.x as well): First, open the Windows PowerShell console as an Administrator and do the following to install PnP.PowerShell module:

  1. Uninstall the Legacy SharePointPnPPowerShellOnline Module if installed already:

    Uninstall-Module SharePointPnPPowerShellOnline -Force –all versions

  2. Install the New PnP PowerShell Module with the following code:

    Install-Module PnP.PowerShell

  3. If you want to install or update to the latest built pre-release of PnP PowerShell, run the following code:

    Install-Module -Name “PnP.PowerShell” -AllowPrerelease

  4. Connect to the SharePoint Online Admin Centre of your tenant with the following code:

    Connect-PnPOnline -Url tenant-admin.sharepoint.com -Interactive

  5. The following command will give you a list of PnP PowerShell commands to design your SharePoint website:

    Get-Command -Module PnP

    In case you would like to uninstall PnP PowerShell again, you can run the following:

    Uninstall-Module -Name “PnP.PowerShell”

    How to Use PnP PowerShell in the Azure Cloud Shell

    Open the Azure Cloud Shell at shell.azure.com and select PowerShell as your shell and enter:

    Install-Module -Name “PnP.PowerShell”

The next time you open the Azure Cloud Shell, PnP PowerShell will be available for you to use.

In Summary

PnP PowerShell proves to be an indispensable tool in SharePoint development services, allowing you to automate repetitive tasks, enhance productivity, and maintain consistency across your SharePoint environment. By following this tutorial to install PnP PowerShell and exploring its resourceful applications, you're well on your way to becoming proficient in SharePoint development and administration with PnP PowerShell.