how to delete SharePoint Group connected sites using PowerShell?

52 Views Asked by At

In SharePoint, I need to delete a SharePoint group connected sites through PowerShell, but i was facing an error

This site belongs to a Microsoft 365 group. To delete the site, you must delete the group

enter image description here

how to delete SharePoint group connected sites using PowerShell?

2

There are 2 best solutions below

0
Ganesh Sanap - MVP On

You can use PnP PowerShell or CLI for Microsoft 365 to easily delete Microsoft 365 group and SharePoint site associated with it.

Example:

Using PnP PowerShell:

Remove-PnPMicrosoft365Group  -Identity <group-id>

Using CLI for Microsoft 365:

m365 entra m365group remove --id <group-id>

References:

  1. Remove-PnPMicrosoft365Group
  2. m365 entra m365group remove
  3. Delete all Microsoft 365 groups and SharePoint sites using PnP PowerShell
  4. Delete all Microsoft 365 groups and SharePoint sites using PnP PowerShell

Important Note: Link #3 and #4 given above deletes all M365 groups and SharePoint sites associated with. DO NOT run those scripts as is in your environment. I have provided those links just for reference to see how to use those commands. You will have to run the specific commands for only one site/M365 group.

0
Xyza_MSFT On

When you delete a Microsoft 365 group, all group resources, including SharePoint site, mailbox conversations, Teams, notebook, and Planner tasks also get deleted. So, to delete a SharePoint group connected site, you must need to delete the Microsoft 365 group first.

Here are four methods to delete a Microsoft 365 group.

1.Go to Microsoft 365 admin center -> Active teams &groups -> Delete the Microsoft 365 group.

2.Use PNP PowerShell.

$AdminSiteURL = "https://tenant-admin.sharepoint.com"
$GroupEmail = "[email protected]"
 
Connect-PnPOnline -Url $AdminSiteURL -Interactive
 
$Group = Get-PnPMicrosoft365Group | Where Mail -eq $GroupEmail
 
Remove-PnPMicrosoft365Group -Identity $Group.id

Write-host "Group Deleted Successfully!" -f Green

3.Use Exchange PowerShell.

Connect-ExchangeOnline -ShowBanner:$False
 
Remove-UnifiedGroup -Identity "[email protected]"
 
Disconnect-ExchangeOnline -Confirm:$False

4.Use Azure AD PowerShell.

#Parameters
$GroupEmail = "[email protected]"
 
#Connect to AzureAD
Connect-AzureAD -Credential (Get-Credential) | Out-Null
 
#Get the Azure AD Group
$Group  = Get-AzureADGroup -Filter "Mail eq '$GroupEmail'"
 
If($Group)
{
    $Prompt = Read-Host "Are you sure want to delete the Group (Y/N)?"
    If($Prompt -eq "Y")
    {
        #Delete the Office 365 Group
        Remove-AzureADGroup -ObjectId $Group.ObjectId
        Write-Host "Group Deleted Successfully!" -f Green
    }
}

Source: https://www.sharepointdiary.com/2018/04/how-to-delete-office-365-group-using-powershell.html