I was looking for a easy way to delete hundreds of test site in a modern SharePoint online env. MS flow didn't to the trick, so I was looking into PowerShell.
Set-Location -Path C:\scripts
#Connect to SPO
$tenantName= "companyName"
$username = "[email protected]"
$password = "SuperSavePassword" | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$Password
Connect-SPOService -Url https://$tenantName-admin.sharepoint.com/ -Credential $cred
Connect-MsolService -Credential $cred
Connect-AzureAD -Credential $cred
Connect-PnPOnline -Url https://$tenantName-admin.sharepoint.com/ -Credentials $cred
Anytime I'm trying to Get-PnPUnifiedGroup
I get an error saying s'thing like:
Get-PnPUnifiedGroup : Exception while invoking endpoint https://login.microsoftonline.com/2092f441-2e68-4313-9252-4794a2e05343/oauth2/token
Yet, my account is a global admin on the tenant.
EDIT:
I found another way, in which I don't have to use 'PNPunifiedGroup'
$sites= Import-Csv C:\Users\xxx\Downloads\DemoToDelete.csv
ForEach ($s in $sites)
{
$group = Get-MSolGroup -SearchString $s.Title
Remove-MsolGroup -ObjectId $group.ObjectId
Remove-SPOSite -Identity $s.SiteUrl -Confirm:$False
}
This deleted like 50% of the sites provided in .csv