Testing with Exchange Server – Tips and Tricks – Part 2 – Creating Mailboxes
Posted by Reka Burmeister in Exchange, Exchange 2007, Exchange 2010, Exchange Testing, IT Professional, Outlook, PST Importer, Software Testing, SysAdmin, email on 30-06-2010
Tags: email, Exchange, Exchange 2007, Exchange 2010, Exchange software testing, Exchange Testing, IT Professional, Outlook, PST, PST Files, PST Importer, Software Testing, SysAdmin
In a previous article I mentioned how to create users and computers in active directory, the first stage of testing the PST Importer (and ESA). The next step is to go to Exchange and create mailboxes to the users that we just created and for further comfortable management, add access permissions to them where needed.
This is much easier in Exchange 2007 than it was in Exchange 2003 as here we can use PowerShell. I would like to mention that in case of using Ex 2007, we don’t even have to create the users in advance, the server will take care of that for you. For the full 2007 PowerShell reference guide please see this page http://technet.microsoft.com/en-us/library/bb123703%28EXCHG.80%29.aspx#NthruR
In short, in order to create a new user type in:
New-Mailbox -Name <String> -Database <DatabaseIdParameter> -Password <SecureString> -UserPrincipalName <String> [-DisplayName <String>] [-FirstName <String>] [-Initials <String>] [-LastName <String>]
You might notice that if you simply type a string in for the password you’ll get an error:
New-Mailbox : Cannot bind parameter 'Password'. Cannot convert value "[given_password]" to type "System.Security.SecureString". Error: "Invalid cast from 'System.String' to ‘System.Security.SecureString'."
The reason for this is that the given password has to be a secure string type. In order to create it, type in the following (has to be separate from the previous command):
$Password = ConvertTo-SecureString '<string>' -AsPlainText –Force
After this you could refer to the given password as $Password.
We usually use this command in two different ways. The first one is to use a scripting language (my preference is Python) to generate the commands with different names. I have a list with the thousand most popular first names and the thousand most popular surnames. My script simply combines the two, giving me quite a lot of options. The second method is to name the users using a counter such as User 1; User 2;… User n and use a cycle in PowerShell to generate all required user names, such as:
$Password = ConvertTo-SecureString '<password>' -AsPlainText –Force
for ($i=0; $i -le 10; $i++)
{
New-Mailbox –Name <name>$i -Database <dbname> -Password $Password -UserPrincipalName <UPname> -DisplayName "<name> $i" -FirstName <firstname> -LastName $i
}
If someone doesn’t like PowerShell or doesn’t have it (e.g. Exchange 2003), the batch files I mentioned earlier used in active directory work just fine. After creating the users using those the mailboxes can be assigned to them fairly easily. In Exchange 2007, we have to start the “create new mailbox” process and select “existing users” in the first window.
This will show all users in AD that don’t have mailboxes. Fortunately multiselection is allowed so we don’t have to handle them one by one. Exchange 2003 doesn’t have this feature but there’s an easy workaround. Do a search using Exchange 2003’s Active Directory Users and Computers application for all users and multiselect them. Right clicking once will open the context menu where we can select “Exchange tasks” and “Create exchange mailbox” from there.
Finally, the command to add full access rights to a specific user so all mailboxes could be opened (and managed) from one outlook:
foreach ($sg in Get-StorageGroup) { if ((Get-ExchangeServer
$sg.Server).Domain.Equals("DomainName.com")) { get-mailboxdatabase
-storagegroup $sg.Identity | add-adpermission -user UserName
-accessrights GenericAll; } }
[...] *Coming up in Part 2 – Reka will cover scripts to create mailboxes in Exchange 2007, and how to…. [...]
[...] This post was mentioned on Twitter by Michael Francis. Michael Francis said: Testing with Exchange Server ? Read about how to easily create Exchange mailboxes – http://bit.ly/bAlkpt [...]