Skip to content

Instantly share code, notes, and snippets.

@aflyen
Last active March 8, 2022 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aflyen/38d4dd33cfd20b5fbecb633cd20da37b to your computer and use it in GitHub Desktop.
Save aflyen/38d4dd33cfd20b5fbecb633cd20da37b to your computer and use it in GitHub Desktop.
Bulk delete modern team sites from SharePoint Online with PowerShell
# Read CSV file with a column "URL" including the full URL to the sites to be deleted
$Sites = Import-Csv .\sites.csv
# Connect to admin site
Connect-PnPOnline -Url https://contoso-admin.sharepoint.com
# Delete all sites to recycle bin
$Sites | ForEach-Object {
Write-Host "Remove: $($_.URL)"
$Site = Get-PnPTenantSite -Identity $_.URL
Remove-PnPMicrosoft365Group -Identity $Site.GroupId
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment