Exchange Server 2007: Bulk creation of mailboxes using Exchange Management Shell
Posted by Bharat Suneja at 7:11 PM
Create a spreadsheet (or you can use a standard text editor like Notepad to create a CSV file) with the following columns. You can add more fields if you wish:Alias,Name,UPN
Add data for new accounts in following lines/rows. Here's what it'll look like:
Alias,Name,UPN
User_One,User One,userone@yourUPNsuffix.com
User_Two,User Two,usertwo@yourUPNsuffix.com
User_Three,User Three,userthree@yourUPNsuffix.com
Save the file as CSV - let's call it CreateRecipients.csv
Now fire up Exchange Management Shell and issue the following command:$Password=Read-Host "Enter Password" -AsSecureString
This will prompt you for a password. The same password will be used as the initial password for all your mailbox-enabled users.
Next, issue the following command:Import-CSV CreateRecipients.csv | foreach {new-mailbox -alias $_.alias -name $_.name -userPrincipalName $_.UPN -database "Mailbox Database" -org Users -Password $Password}
This will create the user accounts and mailboxes.Here's how the shell interprets the above command:
Import-csv CreateRecipeints.csv gets data from the CSV file.
- The filename should be enclosed in quotes if you're providing the complete path with spaces, e.g. "c:\My Scripts\CreateRecipients.csv".
- If you're not running the command from the same directory (folder) where the CSV file is located, you will need to provide the complete path to the file.
- foreach parses through each line in your CSV file, using the first row as a header. All the column headings/names get treated as field names.
- The new-mailbox command, as you may already know by now, creates a new mailbox-enabled user.
- For each variable, you either enter a value at the command line (for instance, we're using the value "Mailbox Database" for the Store), or you can pick up the value from your CSV file provided you have a column for it with a heading. For instance, for the -alias field, we use $_.alias - which tells the script to look for the column called alias in your CSV file and pick up the value from the current row or line.
If running the command on the same server where you want to create the mailboxes, you can simply use the Store name, e.g. "Mailbox Store". To create mailboxes on another server's Store(s), you can use either ServerName\Store, or ServerName\StorageGroup\Store, or even the GUID of the Store. How do you get those??? Use the Get-MailboxDatabase commandlet.
- The -org field stands for OU (or Container) you want to create the accounts in. If all the accounts you create from the CSV file will reside in the same container or OU, you can provide this at the command-line, as we did in the example above. Alternatively, you can include the OU/Container name in your spreadsheet/CSV file in a field - let's say OU - and modify your command to say: -org $_.OUNote: Luckily you do not need to provide the distinguishedName of the OU or Container - simply the name of the OU or Container works.
- The -password field picks up the password from the variable called $password that we created earlier.
The new-mailbox command allows you to enter a lot of attributes for each mailbox-enabled user. These are documented here and also in the Exchange Server 2007 online help. For each attribute you want to populate, add it to your spreadsheet/CSV file.
Updates
July 9, 2007: To create new mailboxes with settings based on an existing mailbox, use the following commands:
$Template = Get-Mailbox "Template Mailbox"
Import-CSV CreateRecipients.csv | foreach {new-mailbox -alias $_.alias -name $_.name -userPrincipalName $_.UPN -database "Mailbox Database" -org Users -Password $Password -templateinstance $Template}
Labels: Exchange Shell, Mailbox

Exchangepedia Blog is read by visitors from all 50 US States and 150 countries world-wide


23 Comments:
How would you create bulk mailboxes for users already in the active directory?
Good work!! please keep it up. And I had the same question as the previous poster....how to mail-enable my already existing users? I guess Exchange 2003 did this automatically?? :-)
Blogged about mail-enabling existing users in response to the first comment - read post titled " Exchange Server 2007: Bulk mailbox-enabling users using Exchange Shell" (http://www.exchangepedia.com/blog/2006/12/id-written-about-how-to-bulk-create.html)
Great Blog!
Is it also possible to put more than one alias address in the script?
Louis,
The alias is the mailNickname attribute - it's not a multi-valued attribute, so it cannot hold more than one values.
Did you want to add additional email-addresses?
Bharat
Worked beautifully. Thanks so much for the intro to PowerShell that I needed!
What other AD attibutes can be added here? I'd like to add a custom attribute (staff ID number). Is there a list of attributes that can can be added to the csv file and imported with each user? Thanks so much.
David,
The last paragraph in the post has a link to Microsoft's online documentation for new-mailbox command, which lists all the parameters that you can add. The list includes custom attributes as well as plenty of others.
Bharat
Thanks Bharat, this blog gives too much info regarding the bulk Ids, and now Im using the script to run (ps1),
I have query here, in the Company field I would like to put the employee number when I start using the script, due to this, most of the time these IDs will show the "INA" and users never update the directory and when we do a random check on the servers these ids will be inactive and we will delete those Inactive IDs.. any solution for this?
will this change the old users passwords as well or will this only change the new incoming users
@Shirish: What's 'INA'? Can you provide more details?
@Kuinten: This post shows how to create new mailboxes (that is, mailboxes with new user accounts in AD).
To simply create mailboxes for *existing user accounts* (no, it does not change passwords): Exchange Server 2007: Bulk mailbox-enabling users using Exchange Shell
thanks, they were scared to use this new method if it would change all the passwords for new and old users, we will give this a try
Hopefully this is the last question, They said that we would have to run 2 different shells win and the exchange shell is there a way to run both without having to do 2 different programs, i guess like a all in one program that will do both
After I ran this it showed this ">>", does that mean that it did not run correctly?
Thanks a lot Bharat!
Can you show me how to passing parameter to that .ps1 script? Let say I want the .csv file name to be passed from command line, not hard-coded in the script?
I have this script that I need to use to import about 3300 users.
## Section 1
## Define Database for new mailboxes
$db="DC-MAILSRV01\Jeannette_City"
## Define User Principal name
$upndom="wiu.k12.pa.us"
## Define OU for new users
$ou="Jeannette City"
## Define CSV File with user information
$csvFile="C:\Apps\IU Prodject\Jeannette SD.csv"
## Section 2
## Import csv file into variable $users
$users = import-csv $csvFile
## Section 3
## Function to convert Password string to secure string
function SecurePassword([string]$plainPassword)
{
$secPassword = new-object System.Security.SecureString
Foreach($char in $plainPassword.ToCharArray())
{
$secPassword.AppendChar($char)
}
$secPassword
}
## Section 4
## Create new mailboxes and users
foreach ($i in $users)
{
$sp = SecurePassword $i.password
$upn = $i.finit + "@" + $upndom
$display = $i.firstname + " " + $i.lastname
New-Mailbox -Password $sp -Database $db -UserPrincipalName $upn $i.finit -FirstName $i.finit -LastName $i.lastname -OrganizationalUnit $OU
}
The 1 problem that I have is, I would like to have first int last name for each account. and this is just making it with the first name, how can I extract that from the first name.
my users reside in the ou
europe\users
so the ou users exists more than once. how should i adjust my csv and my script??
Just a note for using Greek characters ( i suppose other international formats too) with exchange management shell and importing csv files or similars you must save the csv file as UTF-8
Stratis
I am looking to have a script to fill in the following information for me.
First Name, Last Name, Description, Office, Telephone Number, Title, Department, and company. We also will need to be able to add an 2ndary pop mail account if possible. Any help would be appreciated.
Hi, I would like to know if that possible to pass the Password from the CSV just like a "password" column?
I try that with -password $_.password but it doesn't work.
Thanks
HI can somebody tell me if i can update title and other information through csv file
@Anonymous from October 22: Password needs to be a secure string. You can convert plaintext to secure string. If your password field/column name is password:
Import-CSV MyUsersFile.csv | foreach {$password = ConvertTo-SecureString $_.password -AsPlainText -Force; new-mailbox -alias $_.alias -name $_.name -userPrincipalName $_.UPN -database "Mailbox Database" -org Users -Password $password}
Hi all,
We can create users+mailboxes with just one command line
Step 1: $password = read-host "enter password" -assecurestring
Step 2: enterpassword:test@123
OU = Lab
MBX= mbdb3
Domain: Fog.com
1....10 | foreach {new-mailbox -alias "lab$_" -name "lab$_" -password $password -database "mbdb3" -organizationalunit lab -userprincipalname "lab$_@fog.com"}
Post a Comment
Links to this post:
Create a Link
<< Home