We were recently bombarded with spam emails, and some users received multiple emails, some exceeding 10.

With the Microsoft Graph API, we can delete up to 100 emails per mailbox. In PowerShell, we can delete only 10 emails per mailbox. If you don’t have any holds in place, you can rerun the PowerShell purge command, and it should delete an additional 10 emails per mailbox. This would never work for me, as we had always had some kind of hold in place. During the recent attack, we needed to delete more than 10 emails per user mailbox at once.

This is where the Microsoft Graph API comes into play. Today, we will build an app that lets users easily purge emails in bulk. I prefer to create apps so that team members can use them. We need to create an app registration in Azure with application-only access, and for this, we will need a service principal account set up with access to the relevant roles in Purview. So, lets do this first.

Let’s go to Microsoft AzureApp Registrations > New Registration