In SharePoint Online, deleting a site collection is a crucial task when performing cleanups, decommissioning old projects, or managing storage limits. Using PnP PowerShell, administrators can efficiently delete unwanted SharePoint sites while ensuring proper permissions and avoiding unintended data loss.
This guide will walk you through the process of deleting a SharePoint Online site using PnP PowerShell with detailed steps, best practices, and troubleshooting tips.
Prerequisites
Before deleting a site, ensure you meet the following requirements:
Global Administrator or SharePoint Admin Role – Required to delete sites.
PnP PowerShell Installed – If not installed, install it first.
PowerShell Execution Policy – Must allow running scripts.
Backup Important Data – Once a site is deleted, recovery is only possible within 93 days.
Step 1: Install and Import PnP PowerShell Module
If you haven’t installed PnP PowerShell, open PowerShell as Administrator and run:
Install-Module -Name PnP.PowerShell -Scope CurrentUser -AllowClobber -Force
Once installed, import the module:
powershellCopyEditImport-Module PnP.PowerShell
This ensures that all required cmdlets are available in your session.
Step 2: Connect to SharePoint Online
To manage SharePoint Online, establish a connection to the SharePoint Admin Center using the following command:
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -Interactive
🔹 Replace yourtenant
with your actual SharePoint tenant name.
🔹 The -Interactive
flag prompts a login window for authentication.
If using App-based authentication, use:
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -ClientId "Your-App-Client-ID" -Tenant "yourtenant.onmicrosoft.com" -CertificatePath "Path\To\Certificate.pfx"
Step 3: Verify the Site Exists
Before deleting a site, check if it exists to avoid errors.
Get-PnPTenantSite | Where-Object { $_.Url -like "*your-site-name*" }
Replace "your-site-name"
with a part of the site’s actual URL.
This will return site details if it exists.
Step 4: Delete a SharePoint Online Site
Use the following command to delete a SharePoint Online site permanently:
Remove-PnPTenantSite -Url "https://yourtenant.sharepoint.com/sites/SiteToDelete" -Force
🔹 Replace "https://yourtenant.sharepoint.com/sites/SiteToDelete"
with the actual site URL.
🔹 -Force
: Skips confirmation prompts for automated scripts.
This moves the site to the SharePoint Deleted Sites (Recycle Bin) for 93 days.
Step 5: Verify Deletion
After deletion, verify that the site has been removed:
Get-PnPTenantSite | Where-Object { $_.Url -eq "https://yourtenant.sharepoint.com/sites/SiteToDelete" }
If the site does not appear in the results, it has been successfully deleted.
Step 6: Permanently Remove from the Recycle Bin
Deleted SharePoint sites remain in the Deleted Sites section for 93 days. To permanently remove the site:
Remove-PnPDeletedSite -Url "https://yourtenant.sharepoint.com/sites/SiteToDelete" -Force
This action permanently deletes the site and cannot be undone.
To confirm:
Get-PnPDeletedSite
If the site does not appear in the results, it has been permanently removed.
Step 7: Disconnect the PowerShell Session
After performing administrative tasks, disconnect the session to enhance security:
Disconnect-PnPOnline
Common Errors & Troubleshooting
Error | Possible Cause | Solution |
---|---|---|
Access Denied | User lacks required permissions | Ensure you are a SharePoint Admin or Global Admin |
The site does not exist | Incorrect URL or already deleted | Verify the site URL using Get-PnPTenantSite |
PnP PowerShell module not found | Module not installed | Run Install-Module -Name PnP.PowerShell |
Cannot connect to SharePoint Online | Authentication issues | Use -Interactive login mode |