Monday, December 08, 2014

Techie Tip : Powershell script for deleting emails by keyword for Exchange 2013

Another post meant for me because I am so forgetful, but it may be useful for others if they come across this.

OK, not one I need to use very often, but here is a quick script for when you need to delete an email with a specific keyword in the subject from multiple mailboxes




cls
Write-Host ""
Write-Host "The following script deletes emails from a named user/mailbox"
Write-Host "containing a specified string in the Subject of the email"
Write-Host ""

Write-Host "Please enter a name (* wildcards ARE ALLOWED)"
$name = Read-Host '>>'
$name

Write-Host ""
Write-Host "Please enter a SUBJECT' keyword (* wildcards ARE ALLOWED)"
$keyword = Read-Host '>>'
$keyword

Search-Mailbox -identity $name -SearchQuery "Subject:'$keyword'" -deletecontent
exit

No comments:

Post a Comment