Created
August 2, 2024 09:30
-
-
Save reshmee011/5864ab7e4a6a453f2e343d06d72ed70c to your computer and use it in GitHub Desktop.
delete_m365_ConnectedTeamSite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Try { | |
$AdminCenterURL="https://contoso-admin.sharepoint.com/" | |
$SiteURL = "https://contoso.sharepoint.com/sites/test" | |
#Connect to SharePoint admin site | |
Connect-PnPOnline -Url $AdminCenterURL -Interactive | |
#Get the SharePoint Online site | |
$Site = Get-PnPTenantSite -Identity $SiteURL -errorAction Ignore | |
#Delete the Office 365 Group | |
Remove-PnPMicrosoft365Group -Identity $Site.GroupId -errorAction Ignore | |
#permanently remove the m365 group | |
Remove-PnPDeletedMicrosoft365Group -Identity $Site.GroupId -errorAction Ignore | |
#Permanently Delete the SharePoint site | |
$dleted = $false; | |
do { | |
Start-Sleep -Seconds 60 | |
try { | |
Remove-PnPTenantSite -Url $SiteUrl -Force -SkipRecycleBin | |
$dleted = $true; | |
} | |
catch { | |
Write-Host "Delete site" | |
} | |
try { | |
Remove-PnPTenantDeletedSite -Url $SiteUrl -Force -SkipRecycleBin | |
$dleted = $true; | |
} | |
catch { | |
Write-Host "Permanently delete site" | |
} | |
} while (!$dleted)#> | |
} | |
Catch { | |
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment