How to delete and restore groups in O365

This article talks about on how to how to delete and restore groups in O365

Let’s see it step by step delete and restore groups in O365

Open admin center: https://admin.microsoft.com/

Navigate to Teams & groups –> Active Teams & groups

Select the group you want to delete

Delete it

Imp note :

When you delete this group, all data associated with it will be deleted, including group email conversations, group notebooks, documents stored in group files, and the group calendar. Any applications that depend on this group (like Teams, Yammer, Planner, etc.) will also be deleted. Consider copying and saving any data you’d like to keep. You can restore deleted ‎Microsoft 365‎ groups and their data for up to 30 days after you delete them.

Done

Now let’s restore it

Navigate to Teams & groups –> Deleted groups

Select deleted group and hit restore group

We are done here

Now navigate to Teams & groups –> Active Teams & groups –> restored group will be visible

PowerShell script for above manual task viz delete and restore groups in O365

# =========================================
# Script: Delete and Restore M365 Groups
# Author: ChatGPT
# =========================================

# Connect to Microsoft 365
Connect-MgGraph -Scopes "Group.ReadWrite.All"
Select-MgProfile -Name "beta"

# -------------------------------
# Function to Delete a Group
# -------------------------------
function Delete-M365Group {
    param (
        [Parameter(Mandatory = $true)]
        [string]$GroupId
    )

    try {
        Remove-MgGroup -GroupId $GroupId -Confirm:$false
        Write-Host "Group with ID $GroupId has been deleted (soft-deleted)."
    }
    catch {
        Write-Host "Error deleting group: $_"
    }
}

# -------------------------------
# Function to Restore a Deleted Group
# -------------------------------
function Restore-M365Group {
    param (
        [Parameter(Mandatory = $true)]
        [string]$GroupId
    )

    try {
        Restore-MgDirectoryDeletedItem -DirectoryObjectId $GroupId
        Write-Host "Group with ID $GroupId has been restored successfully."
    }
    catch {
        Write-Host "Error restoring group: $_"
    }
}

# -------------------------------
# Example Usage
# -------------------------------

# List all active groups
Write-Host "Fetching all active groups..."
Get-MgGroup | Select-Object Id, DisplayName

# List deleted groups
Write-Host "`nFetching all deleted groups..."
Get-MgDirectoryDeletedItem | Where-Object {$_.OdataType -eq "#microsoft.graph.group"} | 
    Select-Object Id, DisplayName, DeletedDateTime

<# 
USAGE EXAMPLES:
---------------
Delete a group (replace <GroupId> with actual Id)
    Delete-M365Group -GroupId "<GroupId>"

Restore a deleted group (replace <GroupId> with actual Id)
    Restore-M365Group -GroupId "<GroupId>"
#>

Conclusion:

Post reading above article reader will be able to delete and restore groups in O365

Also Read  How to add a Distribution list in O365

You can also read this article https://microbrother.com/how-to-create-or-edit-policies-in-o365/ to create or edit policies in O365

Thank you ☺️

Leave a Comment