Forum Discussion

Dianna1T's avatar
Dianna1T
Copper Contributor
Oct 05, 2020

creating bulks mailboxes

Hello,

 

can you assist me with detailed and simple scrip to create bulk mailboxes? We have a hybrid environment. Exchange 2013. i assign the license in 365. 

  • farismalaeb's avatar
    farismalaeb
    Steel Contributor

    Dianna1T 

    This is a quick simple powershell script that will create the users on preim and enable mailboxes in the cloud

    for ($users;$Users -le 10;$Users++){
    
    $BulkName="MyBulk$($users)"
    $UPN=$BulkName+"@"+$env:USERDNSDOMAIN
    $RemoteRouting="smtp:$($BulkName)@MyOrgtenant.mail.onmicrosoft.com"  #Change the MyOrgTenant with a proper one
    New-ADUser -DisplayName $BulkName  -AccountPassword (ConvertTo-SecureString -String 'P@ssw0rd' -AsPlainText -Force) -SamAccountName $BulkName -Name $BulkName -UserPrincipalName $UPN -Enabled $true
    Enable-RemoteMailbox -Identity $BulkName -RemoteRoutingAddress $RemoteRouting
    }

     

    ---------------------

    If you find this reply helpful, please give it a like or click on Best Response if it was the best answer.

    Thanks

     

    • Dianna1T's avatar
      Dianna1T
      Copper Contributor

      farismalaeb Thank you for your response, can you explain to me the scrip I not savvy reading scripts. So I would not know what to change on it.

      • farismalaeb's avatar
        farismalaeb
        Steel Contributor

        Dianna1T 

        The Bold is the explination

        for ($users;$Users -le 10;$Users++){ Loop start here, with a variable named $user and the loop will keep in running and increasing the value of $user with 1 as long as its less or equal (-le)10. The loop will start from 0

        $BulkName="MyBulk$($users)" TheName of the user and the Increment number from the loop above
        $UPN=$BulkName+"@"+$env:USERDNSDOMAIN #Building the UPN for the user, the $Env:USERDNSDOMAIN, will fetch the domain name as the UPN should be username@domain
        $RemoteRouting="smtp:$($BulkName)@MyOrgtenant.mail.onmicrosoft.com" #Change the MyOrgTenant with a proper one, its your external tenant name πŸ™‚
        New-ADUser -DisplayName $BulkName -AccountPassword (ConvertTo-SecureString -String 'P@ssw0rd' -AsPlainText -Force) -SamAccountName $BulkName -Name $BulkName -UserPrincipalName $UPN -Enabled $true #Creating an On-premise AD user using the variable above and a default password which is P@ssw0rd
        Enable-RemoteMailbox -Identity $BulkName -RemoteRoutingAddress $RemoteRouting #Enable this user to have an email on the Exchange Online, But you will need to make sure that the ADSync include the User Container as this script will place the user there, if you don't want that you can change the default location. 

        #After the script finish, just wait for sometime till the ADSync finish and you will find the user on Exchange Online, Please make sure that you run this with Exchange Management shell loaded,  (Exchange Management Shell)
        }

         

         

        ---------------------

        If this answer solved your issue, please click Best Response and give me a thumb up by clicking like πŸ™‚

Resources