0

I need to put together a list of Mailboxes - specifically the Primary SMTP address - that are forwarding to contacts with a specific domain in the SMTP address. For example, the filter would accept a Mailbox with identity "John Doe" if the Forwarding Address points to a Contact with the primary SMTP address "[email protected]".

I can get the Mailboxes that have a forwarding address set with the following command using the Exchange 2007 Shell.

$forwardingMailboxes = Get-Mailbox | where {$_.ForwardingAddress -ne $Null}

How do I filter $forwardingMailboxes further by accepting only the Mailboxes that are forwarding to Contacts with an SMTP address with a specific domain?

1 Answer 1

1

This may do what you need

Get-Mailbox | where {$_.ForwardingAddress -ne $null} | select forwardingaddress | foreach-object { Get-MailContact $_.forwardingaddress -ErrorAction silentlycontinue } | where { $_.primarysmtpaddress -like '*forwardingdomain.com' }

it pulls out a list of forwarded mailboxes, filters it by those which are forwarded to contacts only, and then filters that by the primarysmtpaddress field to only select the domain you need.

3
  • This is pretty close to what I'm looking for. The command returns a list of the Contacts that are being forwarded to an SMTP address with a specific domain. I need the command to return a list of the Mailboxes that are doing the forwarding. I was able to get that list by assigning the Contacts to a variable and then getting the Mailboxes that have the same contact name. It worked out in my case because the Mailbox names and Contact names are identical. Aug 19, 2016 at 18:11
  • There is a solution to that as well. There exists a -passthru switch which passes the selected value down the pipe. Alternately, and clearer to read, would be to use a multi line version and just build a return object which contains a column with the source mailbox and a second column with the dest mail address.
    – Ian Murphy
    Aug 22, 2016 at 9:23
  • Agree with @IanMurphy that an actual script which pulls and tests the forwarding address, then returns the mailbox object for the ones that are forwarding to a given domain. Use advanced function(s). Pipeline input the domain and the array of mailboxes from get-mailbox, and output an array of mailboxes that forward to that domain.
    – Jeter-work
    Aug 24, 2016 at 16:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .