Exchange 2010 creating Bulk Mailbox and Contacts

Posted on 2014-08-28
Last Modified: 2015-06-17
We have recently acquired a company and they need to start emailing using our corporate email domain.  At this moment we are not ready to ingest their data into our exchange organization.  The new group has 100+ users.  My plan was to create new mailboxes on our exchange 2010 SP1 server and forward the emails to their current email addresses and email system.  They will then set the reply addresses on their email server mailboxes with our corporate email domain.  

Steps include
1) Create external contacts for the new  group in our exchange 2010
2) Set the external contacts to hidden.
3) Create new mailboxes for the new group in our exchange 2010
4) Set forwards on each new mailbox to their external contacts
3) Make the necessary changes on the remote exchange server for the reply from address

I have a CSV file with the contact information.  I am researching creating scripts to the steps above.  I have found individual commands but is there a way to do it in one shot?

the contacttest.CSV file has the following fields:
Name                              Firstname      Lastname      ExternalEmailAddress
John Doe Newcompany      John                       Doe            

So far i have step 1 automated and working using the following
Import-Csv “c:\contacttest.csv” | ForEach {New-MailContact -Name $_.Name -Firstname $_.FirstName -LastName $_.LastName -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit “”}

I try to then use the following script to set all the addresses in the CSV file to hidden:
Import-Csv c:\contacttest.csv | ForEach {Set-MailContact -Name $_.DisplayName -HiddenFromAddressListsEnabled $true}

I get an error:
Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.

If i change $_.DisplayName to $_.Name it moves on but asks for an Identity as follows:
cmdlet Set-MailContact at command pipeline position1
Supply values for the following parameters:

If i type the exact name as its displayed in the name field in the source CSV file (John Doe Newcompany) it works and sets that contact to hidden.

I'll stop there for now.  Any help to get this command to bulk change the newly created contacts to hidden from address book working without prompting for an identity?

Any thoughts or solutions overall to get mailboxes created in bulk and set the forwarding address in one script.

Question by:AVnbm

    Author Comment

    Update on my own case, i figured out the correct command to hide from address list:
    Import-Csv c:\contacttest.csv | ForEach {Set-MailContact -Identity $_.Name -HiddenFromAddressListsEnabled $true}

    I now need to bulk create exchange mailboxes and set the auto forward to the above contacts.  Assistance is appreciated.
    LVL 35

    Expert Comment

    by:Jian An Lim
    okay, i found your question interesting.

    the easiest way is you never create contact (waste of object space)
    eventually these users will be landed in your environment one way or the other
    I will create a user with a mailbox then set the targetaddress to the external address.

    Import-Csv “c:\contacttest.csv” | ForEach { New-mailbox -identity $_.Name  -Firstname $_.FirstName -LastName $_.LastName -OrganizationalUnit “” }

    note: you need to create enough of information to allow to create a new mailbox

    ## this will set the forwarding address
    Import-Csv “c:\contacttest.csv” | ForEach { set-mailbox -identity $_.Name -DeliverToMailboxAndForward $true -ForwardingSMTPAddress $_.ExternalEmailAddress }

    This will just solve the problem.

    Author Comment

    thanks for your reply... The reason i created contacts is because when you click on a mailbox in the EMC, go to the Mail Flow Settings Tab, choose Delivery Options and choose properties... the Forwarding Addresses section is looking for a contact and you are not able to just specify an SMTP address.   You have to choose and existing contact or mailbox from the list.  Am i missing something??

    Since i already created a mailbox for test User John Doe, i am testing out the 2nd part of adding an external address.  I type the command, there is no error it just goes back to a prompt but nothing seems to happen.  I check the Mail Flow Settings Tab/Delivery options for the mailbox and its blank.  I am using the exchange management shell for these commands.

    Am i missing something??

    Author Comment

    More info... if i break down the command for just the one test user:
    set-mailbox -identity jdoe -delivertomailboxandforward $true -forwardingSMTPaddress

    again, it seems to work, no errors, but i don't see the forward in the EMC and its also doesn't seem to be forwarding when i send a test email.

    If i run the command 'Get-mailbox jdoe | fl'  i see that ForwardingSMTPAddress is set but again, doesn't appear to be working when i send a test.

    The command is making the change but its not forwarding email.  Also, not sure i like the fact that it doesn't show up in the EMC.  

    As a test i removed the setting via the Shell, waiting a little while, created a contact object and in the EMC under Mail Flow Settings/Delivery options added that contact object for the same external email address.  Once saved mail starts to forward to the external contact right away.

    Therefore, the forward setting set via the shell is applied but forwarding is not working.  When you remove the setting and add via the EMC by choosing the contact object it appears to be working correctly.  

    LVL 35

    Accepted Solution


    most of the activities can be achieved via powershell so this is the best way.

    one thing i might forget to check is
    by default, you are not allow to forward email outside the organisation.
    get-remotedomain * | fl autoforwardenabled
    whether is true or false (remember it is false by default), you need to change it to true.
    set-RemoteDomain * -AutoForwardEnabled:$true

    if you insist using your way, i will have to get to a test-lab to try it out .. can't remember how to configure it.

    NOte: one way to do so is run the command via EMC and before you hit finish, go to the left bottom corner and get the powershell command that represent what you want to do and work out the bulk method.

    Featured Post

    Why spend so long doing email signature updates?

    Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

    Join & Write a Comment

    Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
    Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video discusses moving either the default database or any database to a new volume.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now