• 1. London, UK
  • 2. Sydney, Australia
  • 3. New York, NY
  • 4. Melbourne, Australia
  • 5. Bellevue, WA
  • 6. Paris, France
  • 7. Moscow, Russia
  • 8. Chicago, IL
  • 9. San Francisco, CA
  • 10. Amsterdam, Netherlands

Wednesday, November 01, 2006

 

Exchange Server 2007: Bulk creation of mailboxes using Exchange Management Shell

Posted by Bharat Suneja at 7:11 PM
Bulk creation of mailboxes (and the accompanying user accounts) in Exchange Server 2003/2000 involved some elaborate scripting effort. This task can now be done fairly effortlessly, thanks to the Exchange Management Shell (EMS). The shell can very easily import/use CSV files saved from a spreadsheet or text editor and create the mailbox-enabled users. Here's how.

Step 1 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

Step 2 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.

Step 3 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.

- The | pipes the data from the CSV to the next command.
- 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 $_.OU
Note: 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: ,

14 Comments:

December 8, 2006 10:42 AM
Anonymous Anonymous said...

How would you create bulk mailboxes for users already in the active directory?

 
January 30, 2007 6:28 AM
Anonymous Anonymous said...

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?? :-)

 
January 30, 2007 6:42 AM
Blogger Bharat said...

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)

 
March 7, 2007 4:23 AM
Blogger Louis Göhl said...

Great Blog!

Is it also possible to put more than one alias address in the script?

 
March 7, 2007 9:18 AM
Blogger Bharat said...

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

 
May 20, 2007 6:18 AM
Anonymous Anonymous said...

Worked beautifully. Thanks so much for the intro to PowerShell that I needed!

 
May 31, 2007 1:49 AM
Blogger David said...

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.

 
May 31, 2007 9:17 AM
Blogger Bharat Suneja said...

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

 
March 25, 2008 3:54 AM
Blogger Shirish said...

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?

 
July 8, 2008 7:30 AM
Blogger Kuinten said...

will this change the old users passwords as well or will this only change the new incoming users

 
July 8, 2008 7:39 AM
Blogger Bharat Suneja said...

@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

 
July 8, 2008 7:51 AM
Blogger Kuinten said...

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

 
July 8, 2008 8:47 AM
Blogger Kuinten said...

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

 
July 17, 2008 9:10 AM
Anonymous Anonymous said...

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