Check Email forwarding using Powershell !!!


Being a system admin is not only about the doing the Job but doing it efficiently.

This post will show you how to find out users who have email forwarding to to any person within the exchange server.

1) Open the exchange power shell.

2) Type the following command.

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

Breaking the code :-
  • Get-mailbox module :- is used to find out the information within the mailbox.
  • Filter {ForwardingAddress -ne $null} :- filters the output with an forwarding emailaddress is not equal to $null (no empty)
  •  ft Name,ForwardingAddress,DeliverToMailboxAndForward : again filter the output with only these columns (name, Forwarding address, deliver to mailbox and forward).
  •  -Autosize : if your output is too big, the full output is not shown and items that are over a certain entry are not shown, to avoid this and to output all details we use -autosize
  • you can also re-direct this output from the screen to a file using 'Export-CSV' parameter. 
  • e.g.  Get-Mailbox -Filter {ForwardingAddress -ne $null} | ft Name,ForwardingAddress,DeliverToMailboxAndForward -Autosize | Export-CSV g:\Email_forwarding_output.csv

Note : Please try the command at your own risk, the owner of this blog takes no responsibility for anything that may go wrong on your exchange server.

5 comments:

  1. Or:

    Get-mailbox | select DisplayName,ForwardingAddress | where {$_.ForwardingAddress -ne $Null}

    ReplyDelete
    Replies
    1. Technically it will work but the performance of filtering at the beginning is better. When you filter with a Where after the Pipe, all of the mailboxes are collected then filtered .

      Delete
  2. Thank You for including the explanation. I copy and use shell commands all the time but understanding what each part does gives me more understanding and control to adjust for my needs.

    ReplyDelete
  3. Thank you for including the great explanation.

    ReplyDelete
  4. You can search as well for external domain forwarding, with the attribute ForwardingSmtpAddress

    ReplyDelete