Powershell script to create inbox rule to move spam to junk folder on all Exchange 2010 mailboxes

With Hexamail Guard you can tag any email that is processed as spam using header or subject tags. The script below uses the simplest case (a subject prefix tag) to move spam to user “Junk E-mail” folders  automatically in Exchange.
Remember to turn off the Spam blocker Block and Delete options if you want all spam to pass through to the users’ mailbox junk folders.
#Get list of all Exchange mailboxes
$list = Get-Mailbox * -ResultSize unlimited

foreach ($entry in $list)
$user = $entry.alias
$check = Get-InboxRule -Mailbox $user | where { $_.name -like "Hexamail Spam" }

if ($check -ne $null)
elseif ( $check -eq $null)
New-Inboxrule -name "Hexamail Spam" -mailbox $user -MoveToFolder "$($user):\Junk E-Mail" -SubjectContainsWords "Potential spam:" -ExceptIfSubjectContainsWords  ("RE: Potential spam:","FWD: Potential spam:") -confirm:$false -priority 999 -force

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s