How to bulk create mailboxes in Exchange 2007 PowerShell
Recently I have been tasked to migrate an existing exchange server 2003 to exchange server 2007. In the old exchange, there are around 300-400 user mailbox that I need to move it to the new exchange 2007 server. At first I started to do the “manual” account creation but after awhile it is quite tedius and tiring. My hands are tired and pain, shouting for better solution…Then I remember that exchange 2007 have it’s own PowerShell, off I go with Google search. ![]()
I don’t have much experience on exchange 2007, but just normal administration I can do without problem. Luckily I am on weekend shift (yup, I’m working while typing this) and I am quite free to search for some simple scripts online. As I know that exchange 2007 comes with the PowerShell which is quite “powerful”. Being powerful means you need to learn the syntax and how to use it.
I found this website from exchangeninjas.com, there is a simple script and guide on how to use it. I tested the script and it work but not to my requirements. I need to do some changes to cater for my needs.
After an hour struggling with the changes and testing, I manage to get what I want. Below are the my modified scripts which I think might look a bit awkward but it did solve my problem. ![]()
## Import data from csv and store it in variable ‘data’
$data = import-csv $args[0]
## Function to convert password into a secure string
function New-SecureString([string] $plainText)
{
$secureString = new-object System.Security.SecureString
foreach($char in $plainText.ToCharArray())
{
$secureString.AppendChar($char)
}
$secureString
}
foreach ($i in $data)
{
$ss = new-securestring $i.password
$upn = $i.NameEmail + “@” + $i.fqdn
new-mailbox -Password $ss -Database $i.database -Alias $i.alias -FirstName $i.FirstName -LastName $i.LastName -DisplayName $i.DisplayName -UserPrincipalName $upn -Name $i.name -OrganizationalUnit $i.ou ; Set-Mailbox -Identity $i.alias -EmailAddressPolicyEnabled $false -PrimarySmtpAddress $upn
}
As you might wonder why I need to use the command Set-Mailbox after the email account creation, this is because the “UserPrincipalName” will be overwrite by exchange mailbox policy. You will need to make sure the checkbox is uptick as below.
I have more than 1 domain on the server and each time to create a new user mailbox, I will need to change the email address as well. Hence I need the second command line to solve the problem. “Set-Mailbox -Identity $i.alias -EmailAddressPolicyEnabled $false -PrimarySmtpAddress $upn”
The above script will not work alone, you need to provide the data for it to execute. You may view/download my sample csv file for the above script.
Download: myList.csv
To use this script, copy and paste it to your notepad and save it as myscript.ps1. Then power up your PowerShell and run the commands as below, remember where you place your files.
c:\temp\myscript.ps1 c:\temp\myList.csv
OK now I have my user mailboxes setup, it’s time to add them to their respective distribution groups…![]()
Related Posts
- How To Create SMTP Connector in Exchange 2007
- How To Export User Mailbox from Exchange 2007
- How To Allow Relay Exception In Exchange 2007 Receive Connector
- Exchange 2007 – Generate Activation Context failed: Event ID 59
- Exchange 2003 Send Emails Locally but not Externally
- Configure Out Of Office Auto Reply for Internet Address In Exchange 2003











































