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”

image

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

}

Nicolas Blank

Nicolas is an Architect, author, and speaker focused on all things Exchange and Cloud at NBConsult. With over 16 years of experience on Exchange, Nicolas consults to customers globally on cloud based and on-premises Exchange as well as ISVs building Exchange focused products. Nicolas has extensive experience using Azure to create public and private Azure based offerings leveraging cloud based principles and common sense. Nicolas currently holds status of MCM Exchange 2010, Office 365 (Microsoft Certified Master), MCSM Exchange 2013, and has been awarded Microsoft MVP (Most Valuable Professional) for Microsoft Exchange since March 2007. Nicolas has co-authored "Microsoft Exchange Server 2013: Design, Deploy and Deliver an Enterprise Messaging Solution," published by Sybex. Nicolas blogs regularly on Exchange and messaging topics at blankmanblog.com, tweets at @nicolasblank, and is the founder of and a contributor to IT Pro Africa itproafrica.com and @itproafrica

nicolasblank has 99 posts and counting.See all posts by nicolasblank

Pin It on Pinterest