List users with email forwarding enabled

by Bharat Suneja on October 18, 2005

Here’s a script written in response to a newsgroup post today on microsoft.public.exchange.admin.

Exchange Server allows you to forward inbound mail for one recipient to another recipient. You can forward messages to the alternate recipient, without delivering a copy to the original recipient (effectively redirecting inbound mail for the recipient), or deliver messages to both original and alternate recipients.


Figure 1: Exchange 2003 allows you to forward mail for one recipient to another recipient using Delivery Options

In Exchange 2003, this is accomplished using Delivery Options from ADUC | Exchange General tab. To forward to an external email address, create a (mail-enabled) Contact in AD.

In Exchange 2007, Delivery Options is found in the Mail Flow Settings tab in a recipient’s properties in EMC.

Listing Users With Forwarding Enabled

Requirement: List users with email forwarding enabled.
Using Saved Queries: On Windows Server 2003, this can be easily accomplished using Saved Queries. Create a new query. From the Find drop-down, select Custom Search. In the Advanced tab, type the following LDAP query:
(&(mailNickname=*)(altRecipient=*))

Screenshot: Saved Queries showing ForwardingEnabled custom query
Figure 2:You can view recipients with forwarding enabled using ADUC’s Saved Queries feature

The other half of the requirement is to actually list the name of the user/mailbox being forwarded to. This is something ADUC can’t do – there’s no choice to add and display the altRecipient in a column next to each user.

The script will show all mailboxes setup to forward to an alternate recipient, the recipient being forwarded to (altRecipient), and also if messages are being delivered to both — the original recipient’s mailbox and the alternate recipient.

In Exchange 2010 and Exchange 2007, you can easily list this information using the shell:

Get-Mailbox -Filter {ForwardingAddress -ne $null} | ft Name,ForwardingAddress,DeliverToMailboxAndForward -Autosize

As reader Charles Howard points out in the comment (dt. Jan 29, 2009), the ForwardingAddress is output as the Active Directory object (john smith domain.net\contacts\someguy) instead of the SMTP address. The following command can output the PrimarySMTPAddress of the recipient:

Get-Mailbox -Filter {ForwardingAddress -ne
$null} | foreach {$recipient = $_; $forwardingsmtp = (Get-Recipient $_.ForwardingAddress).PrimarySmtpAddress; Write-Host $recipient.Name, $forwardingsmtp, $recipient.DeliverToMailboxAndForward }

Updates:

- 11/25/2008: Added Exchange 2007 info and command
- 2/1/2009: Added command to output primary SMTP address of recipient being forwarded to.
- 9/21/2011: Fixed script download link

{ 22 comments… read them below or add one }

1 David Buckley February 26, 2006 at 9:03 am

Bharat, any chance you could help me out and mod this script a little. I ran it as is and there were over 200 users listed. This of course ran off the screen, and this is a report that I need to get across several of my email environments. We are in the process of collapsing email environments, to go form 12 to 1. Having the output sent to file would be brilliant.

Your help is greatly appreciated.

Kind regards,

David Buckley:)

Reply

2 Bharat Suneja February 26, 2006 at 11:36 am

David,

Output to a text file from any script is quite easily accomplished from the command line.

scriptname.vbs >filename.txt
OR
scriptname.vbs >filename.csv
creates a new file.

scriptname.vbs >>filename.txt
appends to an existing file.

I normally include a /f: switch with scripts to output to a file, but forgot to do that in this script. Will add this soon!

Bharat

Reply

3 Anonymous April 3, 2006 at 1:30 pm

I used this code to add to my “Saved Queries” and it worked perfectly. Thanks. I’m also looking for a reporting method to show mailbox usage for my Exchange 2000 server. Do you have any suggestions on reporting on this info?

Reply

4 WTHunter April 3, 2006 at 1:34 pm

I used this code in my “Saved Queries” and it worked perfectly. I am looking for a way to report on my Exchange 2000 users mailboxes to report on mailbox usage. (Whether or not they are actually being used by the Owner) Do you have any suggestions?
email me rod at rodharrison dot com

Reply

5 WTHunter April 3, 2006 at 1:35 pm

I used your code in my “saved queries” and it worked perfectly. I am looking for a method to report on my Exchange 2000 mailboxes to see if they are actually being used by the mailbox owner. Do you have any suggestions on how to do this?

Reply

6 dafa January 12, 2009 at 10:50 pm

On my 2007 Exchange box, the powershell cmd is (notice DeliverToMailboxAndForward):

Get-Mailbox -Filter {ForwardingAddress -ne $null} | ft Name,ForwardingAddress,DeliverToMailboxAndForward -Autosize

Reply

7 Bharat Suneja January 12, 2009 at 11:37 pm

@dafa: Thanks for pointing out – corrected.

Reply

8 Charles Howard January 29, 2009 at 4:18 pm

i know.. very old post. hopefully the author takes a peek.

This command works great but is it possible to get the actual email address that it forwards to instead of just the contact object?

for example:

john smith domain.net\contacts\someguy someguy@someplace.com

Reply

9 Bharat Suneja February 2, 2009 at 5:34 pm

@Charles: Post updated with additional command to spit out SMTP address of the ForwardingAddress recipient.

Reply

10 Anonymous March 23, 2009 at 4:17 am

Bharat,

I’m getting a null error (line 48, character 13) when running the script – am new to vbs scripts so can you help me troubleshoot please?

Matt

Reply

11 Anonymous May 6, 2009 at 12:55 pm

Hi Bharat, how can I redirect the output to a txt file?
thank you very much for you help.

Melissa Monroy.

Reply

12 Anonymous June 4, 2009 at 8:23 pm

Bharat already answered this Q, scroll up and see ;)

Reply

13 Dan July 10, 2009 at 12:05 pm

Any idea why I can't get the altrecipient attribute to take a wildcard string? For instance, to look for any user whose alternate recipient's name starts with an S, the following does not work: (altrecipient=CN=S*)

Typing the whole canonical name out works fine (altrecipient=CN=Smith\, John,OU=Users,DC=acme,DC=com), and so does replacing the search with a plain * it's just using a partial string wildcard that refuses to work.

Reply

14 Anonymous February 4, 2010 at 1:24 pm

Link to the Zip file seems to be broken….

Reply

15 Anonymous April 20, 2010 at 4:34 am

Link to the Zip file seems to be broken….

Reply

16 abu May 2, 2010 at 4:56 am

Hi,

How to take Out Put ib text or csv format

Reply

17 Carlos Martin July 6, 2012 at 8:01 am

Hello,
Is there a way you can output the result of this scrip to a csv or txt file:
Get-Mailbox -Filter {ForwardingAddress -ne
$null} | foreach {$recipient = $_; $forwardingsmtp = (Get-Recipient $_.ForwardingAddress).PrimarySmtpAddress; Write-Host $recipient.Name, $forwardingsmtp, $recipient.DeliverToMailboxAndForward }

Thanks

Reply

18 Eriq September 28, 2012 at 10:18 am

Can you please provide an update for this that will work with Exchange 2010? When I try to run the 2nd command (which shows the actual email address that the messages are being forwarded to), I get the following error for each user:

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
+ CategoryInfo : OperationStopped: (Microsoft.Power…tHelperRunspace:ExecutionCmdletHelperRunspace) [],
PSInvalidOperationException
+ FullyQualifiedErrorId : RemotePipelineExecutionFailed

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
+ CategoryInfo : OperationStopped: (Microsoft.Power…tHelperRunspace:ExecutionCmdletHelperRunspace) [],
PSInvalidOperationException
+ FullyQualifiedErrorId : RemotePipelineExecutionFailed

Reply

19 Jonathan December 30, 2012 at 2:28 am

Hi,
Hope this thread still alive.

Great script, helped me a lot.
Only thing thou, when I try to output it to a txt file (script.vbs>file.txt), I get an empty file, 0KB.

Any idea why?

Reply

20 istrian June 5, 2013 at 1:06 am

Jonathan use this:

cmd

cscript myscript.vbs > c:\scripts\log.txt

Reply

21 Mail solutions August 26, 2013 at 2:32 am

Exchange Server allows you to forward inbound mail for one recipient to another recipient. The script seems really effective. This command works correctly and with great convenience.

Reply

22 Craig December 6, 2013 at 7:57 am

Any chance that this can output into a CSV file? Please and thank you.

Get-Mailbox -Filter {ForwardingAddress -ne
$null} | foreach {$recipient = $_; $forwardingsmtp = (Get-Recipient $_.ForwardingAddress).PrimarySmtpAddress; Write-Host $recipient.Name, $forwardingsmtp, $recipient.DeliverToMailboxAndForward }

Reply

Leave a Comment

{ 1 trackback }

Previous post:

Next post: