Install the PnP PowerShell Module for SharePoint Online (2024)

The PnP PowerShell module has become an indispensable tool for many SharePoint administrators and developers. This open-source module, created by Microsoft’s Patterns and Practices (PnP) initiative, provides a robust set of commands for managing SharePoint Online and SharePoint Server through PowerShell.

In this post, I will provide an overview of the PnP PowerShell module, discuss how to install and update it, demonstrate some key commands and capabilities, and share some of the common tasks to manage your SharePoint environment. Whether you are new to the PnP PowerShell module or looking to get more out of it, this post will help take your skills to the next level. By the end, you’ll have the module installed and connected to SharePoint Online using an authenticated session for executing commands.

Table of contents

  • What is PnP PowerShell?
  • How to Install the PnP PowerShell Module: Step-by-Step
    • Step 1: Uninstall the Legacy SharePointPnPPowerShellOnline Module
    • Step 2: Install the New PnP PowerShell Module
    • Step 3: Register a new Azure AD Application and Grant Access to the tenant
  • Connect to SharePoint Online site using PnP PowerShell
  • Connect-PnPOnline using MFA
  • PnP PowerShell to Connect to OneDrive for Business
  • Managing PnP PowerShell Module
    • Update PnP PowerShell for SharePoint Online
    • What version of PnP PowerShell do I have?
    • Uninstall the PnP PowerShell Module
    • Can I have both the New PnP PowerShell and the Classic PnP Modules?
  • Most Common PnP PowerShell Cmdlets for SharePoint Online
  • Conclusion

What is PnP PowerShell?

Install the PnP PowerShell Module for SharePoint Online (1)

The new PnP PowerShell module PnP.PowerShell is a cross-platform, .net framework-based PowerShell product that can run on any operating system that supports .net core, like Windows, Linux, macOS, etc., and provides 500+ cmdlets to work with Microsoft 365 environment (No support for On-Premises server products, As a side note!) cloud products like SharePoint Online, Microsoft Teams, Microsoft Planner, Security & Compliance, Azure Active Directory, and more.

Some of the key features of PnP PowerShell include:

  • Ability to connect to SharePoint Online and on-premises environments.
  • A wide range of cmdlets for managing sites, lists, libraries, content types, fields, and more.
  • Support for provisioning and deploying SharePoint artifacts.
  • Integration with the SharePoint REST API and CSOM (Client-Side Object Model).
  • Extensibility through custom cmdlets and scripts.
  • Working with SharePoint files and folders.
  • Managing Microsoft 365 users and groups.

If you are administering Microsoft SharePoint, you know that PnP PowerShell is an essential tool for managing your environment. It’s an open-source component and community-provided library with active community members providing support, so there won’t be any SLA or direct support from Microsoft. This article will show you how to install the PnP PowerShell module for SharePoint Online.

How to Install the PnP PowerShell Module: Step-by-Step

Managing SharePoint Online environments often requires executing repetitive administrative tasks – like creating sites, setting permissions, and configuring libraries. Carrying out these tasks manually through the SharePoint admin center can be time-consuming. That’s where the Patterns and Practices (PnP) PowerShell module comes into play.

To install the new PnP PowerShell module, You have to follow these steps:

  1. Uninstall the Legacy SharePointPnPPowerShellOnline Module, if already installed.
  2. Install the New PnP PowerShell Module.
  3. Register Azure AD Application and Grant Access to the tenant.

Let’s get started! Open the Windows PowerShell console as an Administrator and execute these steps to install PnP.PowerShell module.

Check if the classic PnP PowerShell module is installed with the below command:

Get-Module SharePointPnPPowerShellOnline -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending

This returns the Name and version of legacy PnP PowerShell installed on the machine (If any). Uninstall Any previous PnP PowerShell Modules for SharePoint Online installed:

Uninstall-Module SharePointPnPPowerShellOnline -Force -AllVersions

Step 2: Install the New PnP PowerShell Module

How do I install a new PowerShell module? To install the new PnP PowerShell module, use:

Install-Module PnP.PowerShell

This will download and install the PnP PowerShell module from the PowerShell Gallery. How to install PnP PowerShell offline? If needed, You can also use setup files from GitHub, Download the PnP PowerShell Offline Installation package, and install it with the following:

Install-Package C:\Path\File.nupkg

Step 3: Register a new Azure AD Application and Grant Access to the tenant

Register-PnPManagementShellAccess

The final step is granting the tenant access to the PnP Management Shell Multi-Tenant Azure AD Application. On executing the above cmdlet, you’ll be prompted to log in and provide consent for your tenant. You must log in with Global Admin (or Tenant Administrator) permissions and complete this step.

In case you are not a global admin, use: Register-PnPManagementShellAccess -ShowConsentUrl and share the URL you get from this cmdlet with the Tenant Admin, and they can complete this consent step from the URL you share.

Finally, You can verify the installation by getting a list of PnP PowerShell commands:

Get-Command -Module PnP.Powershell

How do I use PnP PowerShell in SharePoint Online? Once you are done with the above steps, You can connect to SharePoint Online through PnP PowerShell scripts with username and password with the following commands:

#Connect to PnP OnlineConnect-PnPOnline -Url "https://Crescent.sharepoint.com/sites/Marketing/" -Credential (Get-Credential)#Get All ListsGet-PnPList

Connect-PnPOnline using MFA

To connect to SharePoint Online using PnP PowerShell MFA (Multifactor authentication): Use the “-Interactive” switch instead of “Credentials” if your account is MFA enabled. Behind the scenes, each cmdlet executes a client-side object model code to achieve functions.

#Connect to SharePoint siteConnect-PnPOnline -Url "https://Crescent.sharepoint.com/sites/Marketing" -Interactive#Retrieve a List$list = Get-PnPList -Identity "Documents"

This retrieves the list with the title “Documents” and assigns it to the $list variable.

If you want to schedule your PowerShell script, You can use either the Windows Task scheduler or Azure Automation! How to Schedule PowerShell Scripts with Azure Automation?

PnP PowerShell to Connect to OneDrive for Business

Microsoft OneDrive for Business – The cloud-based storage and file-sharing part of the Office 365 suite can be managed with PowerShell, too. To access the OneDrive for Business site from PowerShell, you will need to first connect to the OneDrive site by running the following cmdlet: Connect-PnPOnline. Once you are authenticated, you can then run any available cmdlets against your OneDrive for Business site just as you would any other SharePoint Online site. E.g., let’s connect to the OneDrive site and create a new folder:

#Parameters$OneDriveSiteURL = "https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com"$FolderName = "Archives" Try { #PowerShell to Connect to OneDrive for Business Connect-PnPOnline -Url $OneDriveSiteURL -Interactive #ensure folder in SharePoint Online using powershell Resolve-PnPFolder -SiteRelativePath "Documents/$FolderName"}catch { write-host "Error: $($_.Exception.Message)" -foregroundcolor Red}

Managing PnP PowerShell Module

Let’s see how to update it, find the installed module version, and uninstall the module:

How do I update PnP PowerShell? To update the PnP PowerShell to the latest version, run the following:

Update-Module -Name "PnP.PowerShell"

This will download and install the latest version of the PnP PowerShell module on your local machine.

What version of PnP PowerShell do I have?

To check the installed version of PnP PowerShell in your system, use:

Get-InstalledModule -Name "PnP.PowerShell"

Uninstall the PnP PowerShell Module

If you would like to remove the PnP PowerShell, you can run the following:

Uninstall-Module -Name "PnP.PowerShell"

Can I have both the New PnP PowerShell and the Classic PnP Modules?

If you want to use the PnP PowerShell module for SharePoint Server (On-Premises), You can install it along with Pnp.PowerShell module as:

Install-Module -Name SharePointPnPPowerShell2019 -AllowClobber

This script installs the SharePointPnPPowerShell2019 module and makes cmdlets available from this module. You can use “Import-Module SharePointPnPPowerShell2019” on the first line to instruct your script to load and use Cmdlets from this specific module. As a side note, the old SharePointPnPPowerShellOnline module is archived and no longer updated.

At times, You may need to use the CSOM PowerShell scripts with the combination of PnP PowerShell cmdlets, as we don’t have PnP PowerShell cmdlets for each and everything in SharePoint Online: How to Connect to SharePoint online using CSOM PowerShell?

Here are some of the most common PnP PowerShell cmdlets for SharePoint Online from the PnP.PowerShell module.

CmdletDescriptionReference
Connect-PnPOnlineConnects to a SharePoint site. Required before executing most other cmdlets.How to Connect to SharePoint Online using PnP PowerShell?
Get-PnPListRetrieves a list or library from the site.How to Get a List in SharePoint Online using PnP PowerShell?
Add-PnPListItemAdds an item to a list.How to Add a New List Item in SharePoint Online using PnP PowerShell?
Set-PnPListItemUpdates a list item with new data.How to Update List Items in SharePoint Online using PnP PowerShell?
Remove-PnPListItemDeletes an item from a list.How to Delete a List Item in SharePoint Online using PowerShell?
Get-PnPFileDownloads a file from the SharePoint site.How to Download a File from SharePoint Online using PnP PowerShell?
Add-PnPFileUploads a file to a document library or folder.How to Upload Files to SharePoint Online using PnP PowerShell?
Set-PnPFileUpdates properties of a file.How to Update Document Properties in SharePoint Online using PnP PowerShell?
Remove-PnPFileDeletes a file from a document library.How to Delete a File from SharePoint Online Document Library using PnP PowerShell?
Get-PnPWebRetrieves information about the site.How to Get Subsites in SharePoint Online using PnP PowerShell?
New-PnPWebCreates a new sub-site.How to Create a Subsite in SharePoint Online using PnP PowerShell?
Set-PnPWebUpdates properties of the site.How to Change the SharePoint Online Site Title (Name) using PnP PowerShell?
Get-PnPUserRetrieves a user from the site.How to Get All Users in SharePoint Online Site Collection using PnP PowerShell?
Add-PnPGroupMemberAdds a user to a group.How to Add User to a Group in SharePoint Online using PnP PowerShell?
Get-PnPTenantSiteRetrieves a list of site collections.How to Get All Site Collections in SharePoint Online using PnP PowerShell?
New-PnPListCreates a new list or library.How to Create a Document Library in SharePoint Online using PnP PowerShell?

How to Create a List in SharePoint Online using PnP PowerShell?

Remove-PnPListDeletes a list or library.How to Delete a List in SharePoint Online using PnP PowerShell?

How to Delete a Document Library in SharePoint Online using PnP PowerShell?

Get-PnPFolderRetrieves a folder within a list or library.How to Get a Folder in SharePoint Online Document Library using PnP PowerShell?
Add-PnPFolderCreates a new folder within a list or library.How to Create a Folder in SharePoint Online using PnP PowerShell?
Remove-PnPFolderDeletes a folder from a list or library.How to Delete a Folder in SharePoint Online using PnP PowerShell?
Get-PnPFieldRetrieves a field (column) from a list.How to Get List Fields in SharePoint Online using PnP PowerShell?
Add-PnPFieldAdds a new field (column) to a list.How to Add a Column to List in SharePoint Online Using PnP PowerShell?
Remove-PnPFieldRemoves a field (column) from a list.How to Delete a Column from a List in SharePoint Online using PnP PowerShell?
Set-PnPFieldUpdates a field (column) in a list.How to Change List Field Settings in SharePoint Online using PnP PowerShell?
Get-PnPViewRetrieves a view from a list.How to Get List Views in SharePoint Online using PnP PowerShell?
Add-PnPViewCreates a new view in a list.How to Create a List View in SharePoint Online using PnP PowerShell?
Remove-PnPViewDeletes a view from a list.How to Delete a List View in SharePoint Online using PnP PowerShell?
Set-PnPViewModifies a view in a list.How to Update a List View in SharePoint Online using PnP PowerShell?
Get-PnPGroupRetrieves a SharePoint group.How to Get SharePoint Groups from SharePoint Online site using PnP PowerShell?
New-PnPGroupCreates a new SharePoint group.How to Create a Group in SharePoint Online using PnP PowerShell?
Remove-PnPGroupDeletes a SharePoint group.How to Delete Group in SharePoint Online using PnP PowerShell?
Set-PnPSiteSets properties of a site collection.How to Enable Custom Script in SharePoint Online using PowerShell?

How to Change the Site Logo in SharePoint Online using PowerShell?

Get-PnPPropertyBag, Set-PnPPropertyBagRetrieves/sets key-value pairs from the property bag.How to Get-Set Property Bag Values in SharePoint Online with PnP PowerShell?
Add-PnPAppRetrieves installed apps from the site.How to Deploy an App to App Catalog in SharePoint Online?
Install-PnPAppInstalls an app to the site.How to Add an App to SharePoint Online Site using PnP PowerShell?
Uninstall-PnPAppUninstalls an app from the site.How to Remove an App in SharePoint Online using PnP PowerShell?
Get-PnPSiteTemplate, Invoke-PnPSiteTemplateGets/Applies a site template.How to Copy a Site in SharePoint Online using PnP PowerShell?
Get-PnPNavigationNode, Add-PnPNavigationNodeRetrieves/Adds navigation nodes from the site.How to Add Top Navigation Link in SharePoint Online using PnP PowerShell?

How to Add a Link to Quick Launch Navigation in SharePoint Online using PnP PowerShell?

Remove-PnPNavigationNodeRemoves a navigation node from the site.How to Remove a Link in Quick Launch/Top Navigation in SharePoint Online using PowerShell?
Get-PnPTermGroupRetrieves term groups from the term store.How to Export-Import Site Collection Term Store in SharePoint Online using PowerShell?
New-PnPTermGroupCreates a new term group in the term store.How to Create a New Term Group in SharePoint Online using PowerShell?
Remove-PnPTermGroupDeletes a term group from the term store.How to Delete a Term Group in SharePoint Online using PowerShell?
Set-PnPTermSetUpdates a term set in a term group.How to Update a Term Set in SharePoint Online using PnP PowerShell?
New-PnPTermSetCreates a new term set in a term group.How to Create a New Term Set in SharePoint Online using PnP PowerShell?
Get-PnPTermRetrieves terms from a term set.How to Get Terms from a Term Set in SharePoint Online using PowerShell?
Add-PnPTermAdds a new term to a term set.How to Create a Term in SharePoint Online Term Store using PowerShell?
Remove-PnPTermRemoves a term from a term set.How to Delete a Term in SharePoint Online Term Store using PowerShell?

Conclusion

And that wraps up this guide on installing and configuring the incredibly useful PnP PowerShell module for SharePoint Online! As you’ve seen, getting set up with PnP PowerShell is quick and easy with just a few PowerShell commands.

Now that the module is installed, you have access to a vast suite of commands for efficiently administering your SharePoint Online environments. From creating sites, lists, libraries, and columns to applying themes, managing permissions, and more, the possibilities are endless with PnP PowerShell.

Be sure to check out the documentation on the available cmdlets to leverage its capabilities fully. As SharePoint Online continues to evolve, so will the PnP PowerShell module, with new features added regularly.

I hope you found this guide helpful. The PnP PowerShell module can massively boost your productivity as a SharePoint admin or developer. Automating tasks allows you to focus on more strategic initiatives rather than heavy manual configuration.

What is PnP PowerShell?

PnP PowerShell is a set of PowerShell modules that provide a command-line interface for managing and automating tasks in SharePoint Online, SharePoint on-premises, and Microsoft 365 environments. It allows developers and administrators to interact with SharePoint using PowerShell commands.

How to install PnP PowerShell for SharePoint Online?

To install PnP PowerShell for SharePoint Online, open Windows PowerShell as Administrator and run the command: Install-Module PnP.PowerShell

How do I connect to SharePoint Online using PnP PowerShell?

To connect to SharePoint Online using PnP PowerShell, use the Connect-PnPOnline cmdlet. Here’s an example:
Connect-PnPOnline -Url "https://yourcompany.sharepoint.com" -Interactive

How do I get all columns, types, and internal names in my site by PnP PowerShell?

Use: Get-PnPField | Select Title, TypeDisplayName, InternalName
More info: Get Site Columns in SharePoint Online using PowerShell

How do you get all SP library IDs with PnP Online?

To get IDs of all SharePoint Online document libraries, use: Get-PnPList | Where-Object {$_.BaseType -eq “DocumentLibrary”}
More info: Get All Document Libraries in SharePoint Online

How do you create top link navigation in PowerShell?

Use the Add-PnPNavigationNode cmdlet to create a top navigation link to the SharePoint Online site.
More info: Add Top Navigation Link in SharePoint Online using PowerShell

How to use SharePoint Online Management Shell?

The SharePoint Online Management Shell is a PowerShell Module that helps administrators manage SharePoint Online sites. Install the Module “Microsoft.Online.SharePoint.PowerShell”, connect to SharePoint Online with Connect-SPOService, and then start using any available cmdlets.
More info: Connect to SharePoint Online from PowerShell

How do I install SharePointPnPPowerShellOnline module?

If you want to install the legacy SharePointPnPPowerShellOnline module for backward compatibility or to manage SharePoint On-premises versions, use: “Install-Module SharePointPnPPowerShellOnline”
More info: How to Connect to SharePoint Online using PnP PowerShell?

Is PnP PowerShell different from the SharePoint Online Management Shell?

Yes, PnP PowerShell and the SharePoint Online Management Shell are different. The SharePoint Online Management Shell is a set of cmdlets for managing SharePoint Online specifically, provided by Microsoft. In contrast, PnP PowerShell offers a broader range of community-supported commands that often provide more functionality and flexibility.

Can I use PnP PowerShell to manage Microsoft Teams?

Yes, PnP PowerShell includes cmdlets for managing Microsoft Teams, allowing you to automate tasks such as creating teams, adding members, and configuring settings. It provides a convenient way to manage Teams alongside SharePoint and other Microsoft 365 services.

Related Posts

Install the PnP PowerShell Module for SharePoint Online (2024)
Top Articles
Latest Posts
Article information

Author: Terence Hammes MD

Last Updated:

Views: 5890

Rating: 4.9 / 5 (69 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Terence Hammes MD

Birthday: 1992-04-11

Address: Suite 408 9446 Mercy Mews, West Roxie, CT 04904

Phone: +50312511349175

Job: Product Consulting Liaison

Hobby: Jogging, Motor sports, Nordic skating, Jigsaw puzzles, Bird watching, Nordic skating, Sculpting

Introduction: My name is Terence Hammes MD, I am a inexpensive, energetic, jolly, faithful, cheerful, proud, rich person who loves writing and wants to share my knowledge and understanding with you.