Forum Discussion

AshishT1550's avatar
AshishT1550
Copper Contributor
Jun 10, 2021

Exchange online Mailbox Full

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

  • EntilZha's avatar
    EntilZha
    Iron Contributor
    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
    • AshishT1550's avatar
      AshishT1550
      Copper Contributor
      Hey Larry,

      Thank you for the response.
      But I have never tried it and I am not sure as well how to do it.
      • EntilZha's avatar
        EntilZha
        Iron Contributor
        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
  • 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.