Find users that are auto forwarding / redirecting their email in Exchange 2010 using Powershell

Solution 1:

You mean like

get-mailbox -Filter { ForwardingAddress -like '*' } | select-object Name,ForwardingAddress

? Or rather "Inbox rules" which your users would have created in Outlook or OWA? The latter should be trickier, but piping

$mbox = Get-Mailbox; $mbox | Foreach { Get-InboxRule -Mailbox $_ }

(Ryan, thanks for testing and correcting the syntax here) and doing some filtering on non-forwarding/redirecting rules should do the trick.

Solution 2:

I found the following PowerShell commands helpful.

To find Forward Rules:

 foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | where {$_.ForwardTo} | fl MailboxOwnerID,Name,ForwardTo >> d:\Forward_Rule.txt }

To find Redirect Rules:

 foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | where {$_.ReDirectTo} | fl MailboxOwnerID,Name,RedirectTo >> d:\Redirect_Rule.txt }

Source: Microsoft TechNet Forums

Solution 3:

Thanks for these commands.

Here's what I ended up using to find rules that wholesale forward or redirect...

foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | where {$_.RedirectTo -or $_.ForwardTo -and -not ($_.description -match "If the message") } | fl MailboxOwnerId,Description >> rules.txt }

That's to find accounts that are basically using the mailbox as a relay to send everything to a different account. I thought it might be helpful to some.