So You have a mailbox that is filled with spam, phishing or whatever emails that You dont want.
I have to say that Microsoft’s new command (new-compliancesearchaction) seems nice, but doesnt work.
new-compliancesearch and then start-compliancesearch find messages, but thats all. Even these commands would delete emails, there’s a limit for 10 msg per search.
Vanhassa vara parempi (Finnish saying, translates that old is better)
1 2 3 4 5 6 7 8 9 10 11 12 |
$VerbosePreference="Continue" $mbx = get-mailbox AffetedMailbox New-PSSessionOption -OpenTimeout 0 Do { $result = Search-Mailbox -Identity $mbx.UserPrincipalName -SearchQuery 'from:emailaddress' -DeleteContent -force -WarningAction Silentlycontinue write-host $result.resultitemscount -ForegroundColor Green } Until ($result.resultitemscount -eq 0) write-host All items removed specified in search! -ForegroundColor Green |
Above loops search-mailbox cmdlet with the limitation of 10 000 email, but loops it when its done.
These new-pssessionoption with timeout 0 which is kinda self-explaining.
Cheers,