Uncategorized

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

About Michael Bender

Just a geek trying to "share the wealth" with the rest of the world... Michael is a teacher at heart. Coming from a career teaching at a community college and work for 19 years as a system engineer, his passion is for helping people learn the skills necessary to ‘level-up’ their careers, and helping businesses achieve their customer goals. Sharing everything is how he guides his career as everyone wins when you share what you know. Currently, he is a Cloud Ops Advocate at Microsoft. This team focuses on engaging and advocating for Operations-focused communities to the engineering teams in Windows Azure. You’ll find Michael and his #AzOps team at conferences, online, and building great content at docs.com. Michael specializes in Windows Server, Virtualization, PowerShell and Windows Azure. As part of his goal of sharing his knowledge, he has a number of courses published on Pluralsight.com covering PowerShell and Windows Server. He is passionate about the IT Operations community. For the last 8 years, he has led up a global user group called The Krewe.he is the current president and a founding member of The Krewe, a worldwide networking group for IT Pros and Developers. This group provides a global network for the sharing of ideas and solutions for many in the Operations community. For more information, check out The Krewe on Facebook or Twitter.
View all posts by Michael Bender →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.