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?
PnP PowerShell 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:
- Uninstall the Legacy SharePointPnPPowerShellOnline Module if installed already:
Uninstall-Module SharePointPnPPowerShellOnline -Force –AllVersions
- Install the New PnP PowerShell Module with the following code:
Install-Module PnP.PowerShell
- 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
- Connect to the SharePoint Online Admin Centre of your tenant with the following code:
Connect-PnPOnline -Url https://tenant-admin.sharepoint.com -Interactive
- 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 https://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
In this tutorial, we went over how to install PnP PowerShell and discussed multiple different instances of why and where PnP PowerShell is resourceful.
For more information, contact our commerce experts today.