If you ever need to find all the users in your Exchange Organisation whom have a forwarding address configured, but also know what that address is – all you need to do is use this simple Powershell one-liner:
Get-mailbox | select DisplayName,ForwardingAddress | where {$_.ForwardingAddress -ne $Null}
Thank yo very much
Try below command:
Get-mailbox -ResultSize unlimited | select DisplayName,ForwardingAddress | where {$_.ForwardingAddress -ne $Null}
Not working for me at SBS2011 + MSEXCH 2010:
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\Windows\system32> Get-mailbox | select DisplayName,ForwardingAddress | where {$_.ForwardingAddress -ne $Null}
The term ‘Get-mailbox’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:12
+ Get-mailbox <<<< | select DisplayName,ForwardingAddress | where {$_.ForwardingAddress -ne $Null}
+ CategoryInfo : ObjectNotFound: (Get-mailbox:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
You are not using the correct Powershell version. There is a specific version just for Exchange.
This is great! How could I replace the “-ne $null” with something to specify a forward in place to a user? I tried changing “-ne $null” to “-eq “[email protected]”” but that didn’t work. We have some users forwarding to a specific user and would like to know everyone forwarding to that user. TIA
A couple suggestions to improve on this: sometimes forwarding can be configured using the ForwardingSmtpAddress attribute (this may be Exchange Online specific but I’ve definitely seen it in our deployment), so checking for a non-null value there is useful. It’s also much more efficient to specify the filter using the -Filter parameter on Get-Mailbox instead of getting all mailboxes and then using Where.
Get-Mailbox -Filter {ForwardingAddress -ne $null -or ForwardingSmtpAddress -ne $null} | Select DisplayName,ForwardingAddress,ForwardingSmtpAddress
Thanks James (and Andy), that is just what I needed. I refined James’ one-liner with the following code:
$FwdingMBs = Get-Mailbox -Filter {ForwardingAddress -ne $null -or ForwardingSmtpAddress -ne $null}
Write-Host “Mailbox,FowardingSMTPAddress,ForwardingAddress”
foreach ($mb in $FwdingMBs) {
[string]$Output = $mb.DisplayName
if ($mb.ForwardingSmtpAddress -ne $null) {
$Output = “$Output,$($mb.ForwardingSmtpAddress)”
} else {
$Output = “$Output,”
}
if ($mb.ForwardingAddress -ne $null) {
[string]$fwdAddress = (Get-ADObject -Identity $(($mb.ForwardingAddress).DistinguishedName) -Properties mail).mail
$Output = “$Output,$fwdAddress”
} else {
$Output = “$Output,”
}
Write-Host $Output
}
“`r`nScript Completed.”