Removes spam from exchange 2010 with powershell. Creates a log file in
G:\s\Logs\exchange\
Edit the $spam var.
Use
“from:$spam”
for
From and
“subject:$spam”
for
Subject.
$spam = "pravinchauhan1991@yahoo.in"
$today = (get-date).tostring("MM-dd-yyyy")
$ExDBs = "db04","db08","db12","db16","db20","db24","db28"
Foreach($ExDB in $ExDBs)
{
#Defines source and destination
$outfile = 'G:\s\Logs\exchange\SpamCleanUp_' + $today + '_' + $spam + '_' + $ExDB + '.txt'
Get-mailbox -database $ExDB -resultsize unlimited | search-mailbox –searchquery “from:$spam” -LogLevel Full -TargetMailbox discovery -TargetFolder inbox -DeleteContent -force | ft displayname, resultitemscount, resultitemssize >> "$outfile"
}