The PnP PowerShell module is used to manage a range of products in Microsoft 365, including SharePoint Online, Teams, Microsoft Project and Entra ID (ex-Azure AD). PnP is an open-source module, developed and maintained by the community. In this post, we’ll look at how to use the PnP Module cmdlets to perform common SharePoint Online administrative tasks.
The PnP module is based on .Net Core, so it can only be used in versions of PowerShell Core 7.2 or later. Check your version of PowerShell:
$PSVersionTable
To install the PnP PowerShell module from the PowerShell Gallery, run the command:
Install-Module PnP.PowerShell
Check that the PnP module is installed:
Get-Module
View a complete list of available PnP Module cmdlets (over 680):
Get-Command -Module Pnp.powershell
Before using the PnP module for the first time, you need to register an Entra ID (Azure AD) application and grant access to your Microsoft 365 tenant. Run the command:
Register-PnPManagementShellAccess
Sign-in with tenant admin account and grant consent to the requested permissions for the PnP Management Shell.
You can now connect to your tenant’s SharePoint Online Admin Center:
Connect-PnPOnline -Url "https://<Tenant_Name>-admin.sharepoint.com" -Interactive
Use the New-PnPSite cmdlet to create a new SharePoint site.
Types of Sharepoint sites:
- TeamSite — modern Team site collection with Microsoft365 group;
- TeamSiteWithoutMicrosoft365Group — modern site without creating new Microsoft365 group;
- CommunicationSite — communication site collection.
Set the site name, description, and URL of your SharePoint tenant in PowerShell variables:
$SiteTitle ="NY Managers" $SiteDesc = "test site" $SiteURL = "https://tetra.sharepoint.com/sites/nymanagers" New-PnPSite -Type CommunicationSite -Title $SiteTitle -Description $SiteDesc -Url $SiteURL
Connect to the site you have created:
Connect-PnPOnline -url https://tetra.sharepoint.com/sites/nymanagers" -Interactive
To change the title of the site, run the following command:
Set-PnPWeb -Title "New York Managers SharePoint Portal"
After creating a site, you can add a document library:
New-PnPList -Title Contracts -Template DocumentLibrary -OnQuickLaunch
Create a new folder in your SharePoint document library:
$DocLibraryName = "Contracts" Add-PnPFolder -Name Vendors -Folder $DocLibraryName
To create a subfolder in an existing SharePoint folder:
$DocLibraryName = "Contracts/Vendors" Add-PnPFolder -Name “TmpFolder” -Folder $DocLibraryName
Upload any file from your local computer to the specified document library folder on your SharePoint site:
Add-PnPFile -Path "C:\tmp\report.pdf"-Folder "Contracts/Vendors/TmpFolder"
Open the SharePoint Online Admin Centre and make sure that the new site is displayed in the list of active sites.
Now open the new site in your browser and check that the document library has been created and the file has been uploaded.
When you are finished working with the SharePoint Online environment, exit the PnP PowerShell session:
Disconnect-PnPOnline