Exchange online Mailbox Full

Copper Contributor

Hello All, 

 

Can someone please help me with the command to deleted the content in an exchange online mailbox folder.

I ran the compliance search and then tried to purge it but it seems to delete only 10 emails at the time with the purge command. I have a 50Gb folder that I want to clear in the mailbox.

 

Thanks in Advance!

5 Replies
You can still use good old Search-Mailbox cmdlet, as long as you can target the messages with it (you cannot specify a folder). Or do it via an EWS-based script. Or via Outlook/OWA as last resort.
Have you though about using MS Graph API to delete messages from a user's online mailbox?

Here's a snip-it of what I use to clean a service account mailbox.

$uri = "https://graph.microsoft.com/v1.0/users/USER-OBJECTID/messages"
$DelMessage = Invoke-RestMethod -Uri $uri -Headers $Header -Method Get -ContentType "application/json"
$MsgID = $DelMessage.value.Id
Foreach($MsgID_ in $MsgID)
{
Write-host $MsgID_ -ForegroundColor Yellow

$deleteuri = "https://graph.microsoft.com/v1.0/users/USER_UPN/messages/$MsgID_"
$DeletedMesage = Invoke-RestMethod -Uri $deleteuri -Headers $Header -Method Delete -ContentType "application/json"
}

Hope this help
-Larry
Hey Larry,

Thank you for the response.
But I have never tried it and I am not sure as well how to do it.
Hey,

If your unfamiliar with Microsoft Graph, then your best bet is to use Content Search in Microsoft 365 Compliance. I created a New Search using the new Content Search and I was able to successfully deleted 275 emails from one of my Service Account online Mailbox.

-Larry

@Larry Jones 

 

Tried that but it can only delete 10 emails at a time.

We have to run the purge command again and again.