> For the complete documentation index, see [llms.txt](https://support.meetuma.ai/uma-knowledgebase/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.meetuma.ai/uma-knowledgebase/integrations/calendar/microsoft-365/cleaning-up-microsoft-365-events-from-deleted-users.md).

# Cleaning up Microsoft 365 events from deleted users

When an employee leaves the organisation and their Microsoft 365 account is deleted, any meetings they organised, especially in room/resource calendars—**do not get automatically removed**. This can result in **orphaned bookings** that block room availability.

This article explains two methods to clean up such bookings depending on the mailbox status.

***

### Method 1: Using `Remove-CalendarEvents` (preferred for active or recently deleted mailboxes)

This method **cancels all future meetings** organised by the user and **notifies attendees**, including room mailboxes. It only works if:

* The mailbox is still active or within the **30-day soft-delete retention** period.
* You have **Exchange Administrator** privileges.

#### 🔧 Steps

1. **Connect via Powershell to Exchange Online**:

   ```powershell
   Connect-ExchangeOnline
   ```
2. **Preview Future Meetings**:

   ```powershell
   Remove-CalendarEvents -Identity terminated.user@company.com `
     -CancelOrganizedMeetings `
     -QueryWindowInDays 180 `
     -PreviewOnly
   ```

   > Replace `terminated.user@company.com` with the actual user email.\
   > The `-PreviewOnly` flag lets you verify what will be removed.\
   > You can increase `-QueryWindowInDays` up to **1080** to cover longer ranges.
3. **Execute Cleanup** (after confirming preview):

   ```powershell
   Remove-CalendarEvents -Identity terminated.user@company.com `
     -CancelOrganizedMeetings `
     -QueryWindowInDays 180
   ```

***

### Method 2: Using compliance search (for permanently deleted mailboxes)

If the user’s mailbox is **permanently deleted** (past 30 days), use Microsoft Purview (Compliance Center) to **search and hard-delete** meetings from resource mailboxes. This method **does not notify attendees**.

#### Requirements:

* **Compliance Administrator** or **eDiscovery Manager** role.
* A list of **resource mailbox names**.

#### 🔧 Steps

1. **Connect to Exchange Online & Compliance Center**:

   ```powershell
   Connect-ExchangeOnline
   Connect-IPPSSession
   ```
2. **Create and Start the Search**:

   ```powershell
   $Search = New-ComplianceSearch -Name "PurgeExUserMeetings" `
     -ContentMatchQuery 'Organizer:"terminated.user@company.com"' `
     -ExchangeLocation "Room1@company.com","Room2@company.com"

   Start-ComplianceSearch -Identity $Search.Identity
   Wait-ComplianceSearch -Identity $Search.Name
   ```
3. **Purge the Found Meetings**:

   ```powershell
   New-ComplianceSearchAction -SearchName $Search.Name -Purge -PurgeType HardDelete
   ```

   > 🔍 Replace email and room addresses as needed.\
   > Use `Get-Mailbox -RecipientTypeDetails RoomMailbox` to get resource mailbox names.

{% hint style="danger" %}
**It is advisable to run `Remove-CalendarEvents` before deleting** users.
{% endhint %}
