I have 2 OU's of users that each have a mail contact with the same name in a seperate single OU. So Jane Doe would be in Staff\OU1 with jdoe@contoso.com email. Mike Doe would be in Staff\OU2 with mdoe@contoso.com. Then in the OU Contacts\Staff they would each have a contact of their names with email address of username@contoso.com.test-google-a.com. I need to forward all users emails in OU1 and OU2 to their contacts in the contacts\staff OU. Also i need mail to go to their mailbox AND the contact email. Is there a syntax in powershell that would do this for me?

  • Are you trying to do this as a one time operation or set up mail forwarding for future emails? – austinian Jul 22 '15 at 17:04
  • It will be a one time operation that gets repeated. User's are added in bulk here. – Brian Jul 22 '15 at 17:59

Assuming you are working with Exchange mailboxes (it's not terribly clear in your question) Set-Mailbox is your best friend.

You're going to need a for-each loop to retrieve the user's attributes and properly set the destination SMTP address. If you have a whole OU of users to apply changes to, use something like:

Get-Mailbox -OrganizationalUnit <OU> | % {Set-Mailbox -DeliverToMailboxAndForward $true -ForwardingSMTPAddress "($_.Alias)@otherdomain.com"}

IMO the first example in the Set-Mailbox page linked is close to what you are trying to do.

Frankly you should not need the contacts, as it's just something else to manage in this case. However, I might not be parsing your question correctly. If you need to manage contacts, this would be Get-MailUser instead of Get-Mailbox. You can still specify -OrganizationalUnit with Get-MailUser, so you can test that out first.

Instead of ForwardingSMTPAddress property, you would want to specify the property ExternalEmailAddress on Set-MailUser

  • Sorry, yes it's exchange 2007. The organization is in the process of migrating to google apps. The manager of the project has said that they need their email to forward to the .test-google-a.com for the mail to route to google. The local exchange needs to stay in place right now as well. The command you gave me does not need the actual contacts to be created then correct? This just adds a forwarding address right to their domain mailbox? In exchange management console we couldn't specify an address so we had to use a mail contact. This command will get around that though? Thanks – Brian Jul 22 '15 at 17:42
  • Also thank you for the help. I am an IT consultant for this client so i have forwarded your solution to the IT director here as I'm not sure if the contacts were required to be used for any other reason. I will mark as an answer once i get approval from him. – Brian Jul 22 '15 at 18:17
  • This should bypass the need for mail contacts in your directory. If you're setting up any Directory Sync with Google, there might need to be contacts there to facilitate communication back to Exchange. I would think this would be a scenario where you sync your Contacts OU to Google, and not your Users (maybe?). – blaughw Jul 22 '15 at 18:20
  • That may be why it was done like that then. The IT director had said there was a command he could run to set the forwarding to the contacts in bulk, but he wasn't able to find it again. Would there be a command to mass deploy the forwarding rules to the actual mail contacts instead of just specifying the SMTP address? – Brian Jul 22 '15 at 18:41
  • 1
    So i was able to get this working with the following command. Import-Csv c:\faculty.csv | % {Set-Mailbox $_.MbxAlias -ForwardingAddress $_.ContactAlias -DeliverToMailboxAndForward $true} I exported the mailbox list and MbxAlias is the mailbox alias. I edited the list to combine first and last name to firstlast with no space and named the column ContactAlias. Alias IS part of the mail contact but it is the full firstlast name. Thanks again for the help. I really appreciate it. – Brian Jul 27 '15 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.