Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

update all exchange mailboxes to forward to external mail

Posted on 2014-08-01
10
Medium Priority
?
338 Views
Last Modified: 2014-08-15
Hi - I have roughly 500 users in my organization on Exchange 2010.  We are going to Google Apps (K12 environment) and I would like to forward incoming all mail from the Exchange server to our new Google Domain.  My user names are all the same, (e.g. bob.smith@ourexchange.domain = bob.smith@ourgoogle.domain).

Rather than hope my users could write their own rule to forward their mail from the exchange address to the google address, and rather than access each of 500 mailboxes one at a time to forward the email, can somebody help me with a script or the command line(s) to use the Exchange Shell to add a forwarding rule to all of my users mailboxes?  If I could limit it by OU, then I could test/troubleshoot and then phase in the mass-forwarding, but that is not a requirement if it is not an option.

I am thinking that just adding the forward to the google domain and also deliver the message to the original Exchange mailbox would be best, rather than just shoving them all to the Google Account...

Any help the experts can provide is appreciated!
0
Comment
Question by:Stephen York
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 16

Accepted Solution

by:
Joshua Grantom earned 1500 total points
ID: 40234522
Something like this should work.

# Loop though the object returned by Get-Mailbox with each element represented by $mailbox

foreach ($mailbox in (Get-MailBox -ResultSize Unlimited  -OrganizationalUnit yourdomain/Staff)

{

# Create the forwarding address string
$ForwardingAddress=  $mailbox.Name + “.” + $mailbox.sn + "@ourgoogle.domain"

# Check for contact, if not add one

If (!(Get-MailContact $ForwardingAddress -ErrorAction SilentlyContinue))

{

New-MailContact $ForwardingAddress-ExternalEmailAddress $ForwardingAddress- OrganizationalUnit yourdomain/GoogleContacts | Set-MailContact -HiddenFromAddressListsEnabled $true
}

# Set the forwarding address
Set-Mailbox $mailbox -ForwardingAddress $ForwardingAddress -DeliverToMailboxAndForward:$true 

}

Open in new window

0
 
LVL 84

Expert Comment

by:David Johnson, CD, MVP
ID: 40234918
your exchange.domain should equal your google.domain once you change the MX records to point to googlemail.com
0
 
LVL 7

Expert Comment

by:Murali Reddy
ID: 40235005
Here you go, you need not even create any contact objects, unless you have other requirements.

$mailbox= Get-Mailbox -ResultSize "Unlimited"
foreach ($i in $mailbox)
{
[string]$forwardingaddress = ($i.primarysmtpaddress); $forwardingaddress= $forwardingaddress.Replace("ourexchange.domain", "ourgoogle.domain")
Get-Mailbox $i.primarysmtpaddress |Set-Mailbox -ForwardingAddress $forwardingaddress -DeliverToMailboxAndForward $true
}

##replace the smtp suffixes accordingly
###I assumed your statements about the smtp addresses in the post. i.e. "My user names are all the same, (e.g. bob.smith@ourexchange.domain = bob.smith@ourgoogle.domain)"
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40235012
Murali,

He wanted the ability to specify an OU so he could test, I included creating contacts so he could see in EMC which users actually had a forward successfully applied.
0
 
LVL 7

Expert Comment

by:Murali Reddy
ID: 40235028
Thanks Joshu, I missed that. Just a string to add in the first line

$mailbox= Get-Mailbox -ResultSize "Unlimited" -OrganizationalUnit "OU path"

---...dito..---

to check what users are applied, run

Get-Mailbox -resultsize "unlimted" |select name,primarysmtpaddress,ForwardingAddress, DeliverToMailboxAndForward
0
 
LVL 1

Author Comment

by:Stephen York
ID: 40235114
Our domain name is changing so the MX record change is not an option.  

The script is most cool.  Let me try this out.  Thank you!
0
 
LVL 1

Author Comment

by:Stephen York
ID: 40247465
Hmmm, I'm striking out here, but I am sure it is a typo on my part.I created a test OU and placed 2 users in it with mailboxes (etest1 & etest2).  My current domain is ravenna.portage.k12.oh.us, my Google domain is: ravennaschools.us.

My script looks like this for my test OU:

$mailbox= Get-Mailbox -ResultSize "Unlimited" -OrganizationalUnit "OU=Test,ou=BOE,OU=Staff,OU=7 - Controlled Users,DC=ravenet,DC=rcs"
foreach ($i in $mailbox)
{
[string]$forwardingaddress = ($i.primarysmtpaddress); $forwardingaddress= $forwardingaddress.Replace("ravenna.portage.k12.oh.us", "ravennaschools.us")
Get-Mailbox $i.primarysmtpaddress |Set-Mailbox -ForwardingAddress $forwardingaddress -DeliverToMailboxAndForward $true
}

I get this for error results:
Cannot process argument transformation on parameter 'ForwardingAddress'. Cannot convert value "" to type "Microsoft.Exc
hange.Configuration.Tasks.RecipientIdParameter". Error: "Parameter values of type Microsoft.Exchange.Configuration.Task
s.RecipientIdParameter can't be empty. Specify a value, and try again.
Parameter name: identity"
    + CategoryInfo          : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox

Invoke-Command : Cannot write input as there are no more running pipelines
At C:\Users\administrator.RAVENET\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\rsd-e2k10.ravenet.rcs\rsd-e2k10.r
avenet.rcs.psm1:49196 char:29
+             $scriptCmd = { & <<<<  $script:InvokeCommand `
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Command], PSInvalidOperationException
    + FullyQualifiedErrorId : NoMoreInputWrite,Microsoft.PowerShell.Commands.InvokeCommandCommand


Running the get-mailbox gives:
Name                          PrimarySmtpAddress            ForwardingAddress                DeliverToMailboxAndForward
----                          ------------------            -----------------                --------------------------
tester, etest1                etest1@ravenna.portage.k12...                                                       False
tester, etest2                etest2@ravenna.portage.k12...                                                       False



What did I do wrong? (and thank you for helping me)!
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40248616
before your switch to google your email looked like this?

 bob.smith@ravenna.portage.k12.oh.us
0
 
LVL 1

Author Comment

by:Stephen York
ID: 40252955
yes!  And now it looks like bob.smith@ravennaschools.us...
0
 
LVL 1

Author Closing Comment

by:Stephen York
ID: 40264252
I found this script on the web and see that it was modified.  The mod was not correct, but you pointed me in the right direction and I solved the issue -

THANK YOU!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will demonstrate that how to do a PST migration from Exchange Server to Office 365. This method allows importing one single PST, or multiple PST's at once.
Microsoft Jet database engine errors can crop up out of nowhere to disrupt the working of the Exchange server. Decoding why a particular error occurs goes a long way in determining the right solution for it.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question