Using PowerShell to Bulk Create Exchange users with unique passwords
There’s a number of articles which detail how to create an Exchange user from a CSV file using Exchange Management Shell, however most of them harvest a password at runtime by prompting the user to type in credentials. The password is then set for all users. However, what if your users all need to have different passwords assigned to them?
Great question, and I’m glad you asked.
When creating a mailbox using the new-mailbox CMDlet, you are required to specify the password as a secure string, what I’m doing in the script below, is reading the csv file, iterating through it and converting the $_.password field into a secure string. That secure string is then passed over into the new-mailboxname CMDlet, quite simple actually.
Note that in Exchange 2010 we do not need to specify a mailbox server, only the mailbox database hosting the mailbox.
The CSV file format can be whatever you like, however for the sake of the script below at minimum needs to be “Alias,Firstname, Lastname,Name,UPN,OUpath,Database,password”
This allows you to create users, in different OU’s with specified passwords using nothing more than Exchange Management Shell.
Copy and paste the text below, and use as required.
#csv format needs to be as follows:
#Alias,Firstname, Lastname,Name,UPN,OUpath,Database,password#change the name and path of the csv file as required.
$users = Import-CSV C:\scripts\users.csv
$users| foreach{
$Password = convertto-securestring $_.password -asplaintext -force
new-mailbox -name $_.name -alias $_.alias -FirstName $_.Firstname -LastName $_.Lastname -userPrincipalName $_.UPN -database $_.Database -OrganizationalUnit $_.OUpath -Password $Password –ResetPasswordOnNextLogon:$true
}