Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 401 characters in body
Source Link
Emiel
  • 99
  • 2
  • 16

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

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.

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

added 2 characters in body; edited title
Source Link
Gautam Sheth
  • 31k
  • 1
  • 36
  • 62

Delete O365 groups and SP online site with powersheelPowerShell

I was looking for a easy way to delete hunderdshundreds of test site in a modern sharepointSharePoint 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'mI'm trying to 'Get-PnPUnifiedGroup'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.

Delete O365 groups and SP online site with powersheel

I was looking for a easy way to delete hunderds 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

Delete O365 groups and SP online site with PowerShell

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.

Source Link
Emiel
  • 99
  • 2
  • 16

Delete O365 groups and SP online site with powersheel

I was looking for a easy way to delete hunderds 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