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

14 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?
Post a Comment
Links to this post:
Create a Link
<< Home