PnP PowerShell simplifies SharePoint Online site management, automation, and administration. It allows admins to create, update, and manage sites, permissions, lists, libraries, and settings efficiently.
This guide covers site management tasks, including:
Connecting to SharePoint Online
Creating and deleting sites
Managing site settings
Assigning permissions
Step 1: Connect to SharePoint Online
Before managing SharePoint sites, authenticate using MFA or App-Only authentication.
MFA Authentication (Recommended for Admins)
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com" -Interactive
This opens a Microsoft login prompt for authentication.
App-Only Authentication (For Automation & Scripts)
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com" -ClientId "<App_ID>" -Tenant "<Tenant_ID>" -CertificatePath "C:\PnPCert.pfx"
⚠ Note: App-Only authentication is required for automation.
Step 2: Creating a New SharePoint Online Site
To create a new Modern Team Site (without Microsoft 365 group):
New-PnPSite -Type TeamSite -Title "Project Alpha" -Url "https://yourtenant.sharepoint.com/sites/ProjectAlpha" -Owner "admin@yourtenant.onmicrosoft.com"
For a Communication Site:
New-PnPSite -Type CommunicationSite -Title "Company News" -Url "https://yourtenant.sharepoint.com/sites/CompanyNews"
For a Classic Team Site:
New-PnPSite -Type TeamSiteWithoutGroup -Title "Classic Team" -Url "https://yourtenant.sharepoint.com/sites/ClassicTeam"
Step 3: Retrieve and Manage Sites
Get a List of All Sites
Get-PnPTenantSite
This returns all sites in the tenant.
Get Details of a Specific Site
Get-PnPSite -Includes Url, Title, Owner
Update Site Properties
Modify site settings (e.g., Storage Quota, Sharing Capabilities):
Set-PnPTenantSite -Url "https://yourtenant.sharepoint.com/sites/ProjectAlpha" -StorageQuota 5120 -SharingCapability ExternalUserSharingOnly
Step 4: Managing Site Permissions
Add a Site Owner
Set-PnPSite -Url "https://yourtenant.sharepoint.com/sites/ProjectAlpha" -Owner "newowner@yourtenant.com"
Add a User to a Group
Add-PnPUserToGroup -LoginName "user@yourtenant.com" -Group "Members" -Web "https://yourtenant.sharepoint.com/sites/ProjectAlpha"
Grant Site Collection Admin Permissions
Set-PnPTenantSite -Url "https://yourtenant.sharepoint.com/sites/ProjectAlpha" -Owners "admin@yourtenant.com"
Step 5: Deleting a SharePoint Site
Move Site to Recycle Bin
Remove-PnPTenantSite -Url "https://yourtenant.sharepoint.com/sites/OldSite"
⚠ Note: The site moves to the SharePoint Deleted Sites (Recycle Bin).
Permanently Delete a Site
Remove-PnPTenantSite -Url "https://yourtenant.sharepoint.com/sites/OldSite" -Force
⚠ Warning: This action cannot be undone.
Step 6: Restore a Deleted Site
If a site was deleted within 93 days, restore it:
Restore-PnPTenantSite -Url "https://yourtenant.sharepoint.com/sites/OldSite"
Step 7: Disconnecting from SharePoint Online
To ensure security, disconnect after completing tasks:
Disconnect-PnPOnline
Common Issues & Solutions
Issue: “Access Denied” while running a command
✔ Solution: Ensure your account has Global Admin or SharePoint Admin roles.
Issue: “The site already exists” when creating a new site
✔ Solution: Run Get-PnPTenantSite
to check if the URL is already in use.
Issue: “App-Only authentication is required”
✔ Solution: Use App-Only authentication for automation scripts.