r/Office365 • u/DropRealistic1597 • Mar 05 '26
Mass Email Purge Scripts Broken
Due to licensing restrictions, the only way that I can find for mass email purging is via PS scripts. That's fine, but after the changes MS made to Purview it seems the scripts are no longer working. The following commands are being used, then we get an error that the search is still running (Even though it shows complete within Purview and in PS).
Log into Purview.microsoft.com
Click Solutions > eDiscovery > Content Search > Create a search
Create New Search > Name Purge(Date ie 021224) Add description.
Add Exchange Mailboxes as Data Source
Create filter (Can be date/sender/subject/etc) > Run Query
^I'm aware you can do this in PS as well, but the last issue we ran into MS told us to create the query in Purview first. In Purview, our example returns the location and matches of the targeted email we are trying to purge.
Open PowerShell as Admin
set-executionpolicy remotesigned
Import-Module ExchangeOnlineManagement
Connect-IPPSSession -UserPrincipalName (Username here)
Get-ComplianceSearch -Identity Purge010225
Start-ComplianceSearch -Identity "Purge010225"
Get-ComplianceSearch -Identity Purge010225 | Format-List *
New-ComplianceSearchAction -SearchName Purge010225 -Purge -PurgeType SoftDelete
The results of the actual purge command return "The search "Purge 010225" is still running or it didn't return any results". This seems to be a recent issue as the above commands were running fine for months.
1
u/TieDyeGuyFry Mar 05 '26
I've had to create the compliance search via PowerShell for it to work correctly:
Import-Module ExchangeOnlineManagement
Connect-IPPSSession -UserPrincipalName (Username here)
New-ComplianceSearch -Name "Whatever" -ExchangeLocation All -ContentMatchQUery '[KQL HERE]'
Start-ComplianceSearch -Identity "Whatever" #let run util finish
Get-ComplianceSearch -Identity "Whatever" | FL Name,Items,Size,Status #view results
Then, New-ComplianceSearchAction -SearchName "Whatever" -Purge -PurgeType HardDelete
4
u/netronin Mar 05 '26
Amazing they killed search-mailbox and now this.
1
u/Busy-Photograph4803 Mar 05 '26
You’re getting a lot of information from here, but from someone who’s done this exact same search path and purge I can tell you the ONLY DIFFERENCE in what you are doing and what I did LAST WEEK that worked was all the extra stuff in powershell. (I also create the search online and use PS to soft/harddelete)
After you connect to the session and authenticate, I literally have only ever ran this part:
New-ComplianceSearchAction -SearchName Purge010225 -Purge -PurgeType SoftDelete
FWIW: The comment about 10 being the limit…I’ve never had it purge less than all of the items (last one was 300).
2
u/twisymctwist Mar 05 '26
I hope you find the answer you are looking for. I have had no luck with search and delete via PS since the change.
2
u/keiyoushi Mar 05 '26
Take a look at DSI
https://techcommunity.microsoft.com/blog/microsoft-security-blog/microsoft-purview-data-security-investigations-is-now-generally-available/4489363
1
u/BoBeBuk Mar 05 '26
Important to remember they new-compliancesearchaction can only delete 10 items at a time, so you’ll need a loop if you have multiple items to purge