If you are running Microsoft Exchange and need a quick way to determine what mailboxes are forwarding email, then this Powershell script is for you. In order for this script to run, you will need at least the Exchange Management tools installed on the computer from which the script will be run.
Note: this script can be easily extended to email the results using my previous article on how to Send Email With Powershell.
################################################ # # ExportForward.ps1 # Author: Matthew Marable # Updated: Sept 19, 2012 # # Description: # Outputs mailboxes with or without forwards # ################################################ # Input parameter param([string]$type = "no") # Add Exchange Tools to Environment Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 # Select Forward Or Not if ($type -eq "no") { # Get Mailboxes Without a Forward $fwds = Get-Mailbox | Where-Object { $_.ForwardingAddress -eq $null } | select Name # Loop Through Forwards foreach ($fwd in $fwds) {$fwd | Select Name} # Export Data to File $fwds | Out-File "No_Email_Forward.txt" } else { # Get Mailboxes With a Forward $fwds = Get-Mailbox | Where-Object { $_.ForwardingAddress -ne $null } | select Name, ForwardingAddress # Loop Through Forwards foreach ($fwd in $fwds) {$fwd | add-member -membertype noteproperty -name “ContactAddress” -value (get-contact $fwd.ForwardingAddress).WindowsEmailAddress} # Export Data to File $fwds | Out-File "Email_Forward.txt" }