I'm encountering issues with a script intended to purge specific emails, particularly phishing ones, from our system. I suspect it might be failing due to our Tenant not being set up for Microsoft Purview, which isn't an expense we can manage right now.
I've tried using the script directly, but it didn't yield any results. The script prompts like 'Search Name to be Created?' and 'Sender Address?' didn't trigger as expected. Afterward, I attempted to modify the script to test it with some emails I had prepared, but still no success.
There were no error messages—everything just seems to run without actually doing anything. I've executed it both in the ISE and the Exchange Management Shell, ensuring I'm running them with admin privileges and that I'm correctly connected to the environment.
We previously managed to purge emails using the Message Trace feature in the Exchange Admin Center, but that option seems to be unavailable now. We're operating in a hybrid environment and the service account I'm using has Exchange Administrator privileges, which I prefer to keep disabled until needed.
Is there a way to make this script work, or are there alternative methods? I'm also exploring a two-part script that involves using an App Password for a service account, but it's not functioning as intended either. Any insights would be greatly appreciated!
3 Answers
The API for Purview changed last year, so that script you have likely won’t work anymore. Even when it did, it could only delete 10 emails at a time unless you put it in a loop. A better approach might be using Microsoft Graph to search through each mailbox and delete the emails you want.
To run that script successfully, you’ll need the eDiscovery Manager or Admin role in Microsoft Purview. Without those permissions, the script won't work as intended.
Honestly, you've not shared much about what you've tried or what went wrong. If there are no errors but it's still not working, have you considered running the script line by line to identify where it fails? That might provide you with some clues on what to fix.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically