We needed a way of creating 200+ mailboxes in an Exchange 2010 – Office 365 Hybrid. The best way was to create the accounts locally, let the AD sync tool create the accounts into Office 365 then assign a licence to the users (I’m sure we could automate that too, but this will not be a huge issue)

So you need a few things to make it all work

 

first, the base script.

 

New-RemoteMailbox -Alias Max.Person-Name "Max.Person" -FirstName Max -LastName Person -DisplayName "Max Person" -UserPrincipalName Max.Person@emaildomain.com -OnPremisesOrganizationalUnit CloudUsers

Once you have that working you can progress to the next step

Call for a password to use
$Password=Read-Host “Enter Password” –AsSecureString

Import-CSV CreateMailboxes.csv | ForEach {New-RemoteMailbox -Alias $_.alias -Name $_.name -FirstName $_.Firstname -LastName $_.Lastname -DisplayName $_.name -UserPrincipalName $_.UPN -OnPremisesOrganizationalUnit CloudUsers -Password $Password}

This will call information from a CSV file

the CSV has to look like this

Alias,Name,Firstname,Lastname,UPN
Max.person,Max Person,Max,Person,max.person@emaildomain.com

one line per user

But this will take ages to fill in all this information.

This is where Excel comes in. Simply enter in the First and Last name, then all other fields are auto filled.

ExcelUserCreateer

Excel file is here CreateMailboxes

Update the domain name as needed, fill that down, fill down A and B

Enter in users names as needed.


Then once you are done, save the file as a CSV. Run the script above then watch all the users get created.


Oh and if you want each user to have a different password, simply add in another line in the Excel file, then change 

-Password $Password}

to
-Password$_.password}

If you want to create users from  a password in a file, use this code

Import-CSV CreateMailboxes.csv | ForEach {New-RemoteMailbox -Alias $_.alias -Name $_.Name -FirstName $_.Firstname -LastName $_.Lastname -DisplayName $_.name -UserPrincipalName $_.UPN -OnPremisesOrganizationalUnit CloudUsers -Password (ConvertTo-SecureString -String $_.Password -AsPlainText -Force)}

this will then use the password from the file.

To then force a sync to Office 365

Login to the Directory Sync Server

Open PowerShell

Type Import-Module DirSync  and then press ENTER.

Type Start-OnlineCoexistenceSync  and then press ENTER.

« »