none
Powershell Script to Bulk Create Exchange Mailbox (On Prem) RRS feed

  • Question

  • Hello!

    I have a really old script that enables a mailbox for a single user. I am looking for one that will help me create a bulk at once. Below is the single user script that I use daily for exchange on prem. Any help is greatly appreciated.

    Step 1:

    $user = Read-Host 'Please enter new mailbox username'
    Enable-remotemailbox -identity $user -primarysmtpaddress $user@company.com -remoteroutingaddress $user@company.com
    Enable-remotemailbox -identity $user -archive
    Write-Host "To complete mailbox creation run a DirSync"

    Step 2: after waiting 10 minutes

    $user = Read-Host 'Please enter mailbox username'
    set-remotemailbox -identity $user -emailaddresses @{add="$username@company.com"}}


    Saturday, July 4, 2020 4:17 AM

All replies

  • Hello,

    Please try the below commands in the test environment before running in production

    #EnableRemoteMailbox
    #Prepare the CSV with Names and run the below command. Make sure to call the header of the CSV as "Name"
    $Users = Import-csv C:\Temp\EnableRemoteMailbox.csv
    $Users | ForEach-Object {Enable-RemoteMailbox -identity $_.Name -Primarysmtpaddress ($_.Name+'@domain.com') -RemoteRoutingAddress ($_.Name+'@domain.com')}
    
    #Enable Archive for the same list of above users
    $Users | ForEach-Object {Enable-RemoteMailbox -identity $_.Name -Archive}
    
    #EmailAddress
    #Prepare the CSV with Name and emailaddress and run the below command
    $Users = Import-csv C:\Temp\EmailAddress.csv
    $Users | Foreach-object {Set-remotemailbox -identity $_.Name -Emailaddresses @{add=$_.NewEmailAddress}}
    


    Thanks,
    Ashok M My blog
    ________________________________________________________________
    Please mark the reply as an answer if you find it is helpful :-)
    ________________________________________________________________

    • Proposed as answer by Ashokm_14 Wednesday, July 8, 2020 6:10 AM
    Saturday, July 4, 2020 7:49 PM
  • Hi!

    First I would really like to thank you for your help!

    I had a question concerning the script. Do I need to create another import file with email address (@mycompany.com) if usually the single script just references the user name in order to complete the last command? 

    I am just trying to understand it as I do not have a test environment. 

    $user = Read-Host 'Please enter mailbox username'
    set-remotemailbox -identity $user -emailaddresses @{add="$username@company.com"}}

    is now:

    #EmailAddress
    #Prepare the CSV with Name and emailaddress and run the below command
    $Users = Import-csv C:\Temp\EmailAddress.csv
    $Users | Foreach-object {Set-remotemailbox -identity $_.Name -Emailaddresses @{add=$_.NewEmailAddress}}

    so I need a Name column & a emailaddress which would be the @company.com?

    Thank again!!

    Sunday, July 5, 2020 2:22 AM
  • Hi,

    You can try the below command and in case if it doesn't work, then amend the CSV with the email address and run the last command shared earlier,

    $Users | Foreach-object {Set-remotemailbox -identity $_.Name -Emailaddresses @{add=($_.Name+'@domain.com')}}


    Thanks,
    Ashok M My blog
    ________________________________________________________________
    Please mark the reply as an answer if you find it is helpful :-)
    ________________________________________________________________

    Sunday, July 5, 2020 5:46 AM
  • Hi Nightangel03,

    You need to prepare a CSV for the AD account that you want to enable mailbox:

    Then you could use this script to enable mailbox for this users:

    $users = Import-Csv c:/temp/users.csv
    $companyName = "@domain.com"
    foreach ($user in $users){
        $addreess = $user.name1 +$companyName
        Enable-remotemailbox -identity $user.name1 -primarysmtpaddress $addreess -remoteroutingaddress $addreess
        Enable-remotemailbox -identity $user.name1 -archive
    }

    Then you could use this script to add second name to this mailbox:

    $users = Import-Csv c:/temp/users.csv
    $companyName = "@domain.com"
    foreach ($user in $users){
        $NewAddreess = $user.name2 +$companyName
        Set-RemoteMailbox -identity $user.Name1 -emailaddresses @{add=$NewAddreess}
    }

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    • Proposed as answer by Ashokm_14 Wednesday, July 8, 2020 6:10 AM
    Monday, July 6, 2020 6:57 AM
    Moderator
  • Just to check if there are any updates. If the above suggestion helps, please be free to mark it as an answer, this will make answer searching in the forum easier and be beneficial to other community members as well.

    Thanks,
    Ashok M My blog
    ________________________________________________________________
    Please mark the reply as an answer if you find it is helpful :-)
    ________________________________________________________________

    Wednesday, July 8, 2020 6:08 AM
  • Hi Nightangel03,

    I am writing here to confirm with you how thing going now?

    If the above suggestion helps, please be free to mark it as an answer for helping more people.

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Thursday, July 9, 2020 7:11 AM
    Moderator
  • Hi Nightangel03,

    Haven't received your update for a long time, any update now?

    If the above suggestion helps, please be free to mark it as answer for helping more people.

    This Exchange Server 2013 - General Discussion Forum will be migrating to a new home on Microsoft Q&A, please refer to this sticky post for more details.

    Regards,

    Kyle Xu


    Exchange Server 2013 - General Discussion forum will be migrating to a new home on Microsoft Q&A! We invite you to post new questions in the new forum.

    For more information, please refer to the sticky post.

    Wednesday, July 29, 2020 2:42 AM
    Moderator