Creating Multiple Mailboxes with Powershell


I was prepping for my Exchange classes client lab this afternoon. I came across a need for each student to have there own mailbox on the Test exchange server. I could have created each mailbox and associated user by hand, but I figured "Let's Try Powershell...or the Exchange Management Shell to be more correct".

Anyway after about an hour of tinkering, I came up with a script that will allow you to create multiple mailboxes from a .CSV file, and base the mailbox on an existing mailbox. This would work great if you had a bulk of new hires or just a need to create a lot of mailboxes.

First I created a CSV file that included the Alias, Name and UPN fields.
Alias,name,upn
User01,User 01,user01@itsallgeek2mike.com

Next, I created a basic mailbox called Template to use as my copy source mailbox.

Finally, I ran the following powershell script to create the new mailboxes:
## Bulk Creation of Mailboxes in Exchange 2007
## Created by Michael Bender
## Requires creation of a CSV file called CreateRecipients.csv located in the
## root of c: or directory of your choice. If you change the directory, you will need to

## Set Script Variables
$CopyMb = Read-Host "Enter Name of Mailbox to Copy"
$Template = get-mailbox $CopyMb
$Pwd = Read-Host "Enter password" -AsSecureString
$MBDb = Read-Host "Enter Exchange Database"
$Db = get-mailboxdatabase $MBDb
$CSV = Read-Host "Enter location of CSV file (e.g. c:\NewMailboxes.csv)"

## CSV Import and Mailbox creation
Import-CSV $CSV | % {new-mailbox -alias $_.alias -name $_.name -userPrincipalName $_.UPN -database $Db -org Users -Password $Pwd -templateinstance $Template}


The mailboxes create properly. However, I keep getting an error referring to the new-mailbox cmdlet and a null value.

I'll keep you posted on the progress...

Mike

Comments