When you get a virtual server or a vmForge Virtual Data Center from us, you can choose to manage it yourself or have us take care of it.  If you choose ipHouse management on a Windows virtual machine, I will probably be involved with your server management. Here is a recent task related to that role.

I hope others find it helpful.

I was adding a list of users to an Exchange 2010 server.  There is a quick way and a slow way to do that. The quick way and slow way trade places when the list grows to a certain size. The quick way is to open Exchange Management Console, expand Recipient Configuration, and click New Mailbox.  Type in the proper values and click next a few times, then click Finish.

The slow way is to create the PowerShell commands to add the mailboxes from a text file containing all the user data and paste it into PowerShell. It is also the quick way, if you have enough users to add.

I’m using awk to do the text processing. You can do this all within PowerShell, but I have not made myself familiar enough with PowerShell’s text manipulation features for it to be my go-to tool. All of my Exchange servers are virtual machines and I use remote desktop to connect to them, so I can paste right from bash terminal into the remote desktop window.  Here’s the procedure.

First, I make a text file containing the following (space-separated in this example):

First name, last name, alias, email address, password.

Alice Adams aadams aadams@corp.domain.com Password1
Bob Baker bbaker bbaker@corp.domain.com Password2
Charlie Carter ccarter ccarter@corp.domain.com Password3
Dan Davis ddavis ddavis@corp.domain.com Password4
Ed Evans eevans eevans@corp.domain.com Password5
Frank Foster ffoster ffoster@corp.domain.com Password6

Then I run this command at my bash prompt to build the PowerShell commands I will paste into the Exchange Management Shell.

awk -F" " '{print "New-Mailbox -Name", "'\''" $1,$2 "'\''", "-Alias", "'\''" $3 "'\''", "-UserPrincipalName", "'\''" $4 "'\''", "-SamAccountName", "'\''" $3 "'\''", "-FirstName", "'\''" $1 "'\''", "-LastName", "'\''" $2 "'\''", "-Password (ConvertTo-SecureString -AsPlainText -Force -String", "'\''" $5 "'\''" ")", "-ResetPasswordOnNextLogon \$false" }' userlist.txt

If I were using tab-separated values, the command would begin like this.

awk -F"\t" ...

This is big, but it is just a straightforward awk one-liner. It looks weird because there are several awkward ways to do that on the command line with awk and no pretty ones. The “‘\”” peppered all over the place just escapes a single quote.

Also, the command I generate contains the following little piece of magic:

(ConvertTo-SecureString -AsPlainText -Force -String 'Password1')

Exchange expects passwords as a “SecureString”. This data type is encrypted and is handled specially by PowerShell. In this case, I am converting the astoundingly bad password, “Password1″ from plaintext to a SecureString so that the New-Mailbox cmdlet will accept it.

If you try to put the password in as a regular string without doing this, the Exchange Management Shell spits back the following nastygram:

Cannot process argument transformation on parameter ‘Password’. Cannot convert the “Password1″ value of type “System.String” to type “System.Security.SecureString”. +CategoryInfo : InvalidData: (:) [New-Mailbox], ParameterBindin…mationException +FullyQualifiedErrorId : ParameterArgumentTransformationError,New-Mailbox

Keep in mind here that you are bypassing an intentional security feature, which is why the ‘-Force’ option is required.  These passwords will show up in your command history and the memory used to store theses strings will not be subject to the fastidious data security policies that PowerShell applies to SecureString items.

The output ends up looking like this:

New-Mailbox -Name 'Alice Adams' -Alias 'aadams' -UserPrincipalName 'aadams@corp.domain.com' -SamAccountName 'aadams' -FirstName 'Alice' -LastName 'Adams' -Password (ConvertTo-SecureString -AsPlainText -Force -String 'Password1') -ResetPasswordOnNextLogon $false
New-Mailbox -Name 'Bob Baker' -Alias 'bbaker' -UserPrincipalName 'bbaker@corp.domain.com' -SamAccountName 'bbaker' -FirstName 'Bob' -LastName 'Baker' -Password (ConvertTo-SecureString -AsPlainText -Force -String 'Password2') -ResetPasswordOnNextLogon $false
New-Mailbox -Name 'Charlie Carter' -Alias 'ccarter' -UserPrincipalName 'ccarter@corp.domain.com' -SamAccountName 'ccarter' -FirstName 'Charlie' -LastName 'Carter' -Password (ConvertTo-SecureString -AsPlainText -Force -String 'Password3') -ResetPasswordOnNextLogon $false
New-Mailbox -Name 'Dan Davis' -Alias 'ddavis' -UserPrincipalName 'ddavis@corp.domain.com' -SamAccountName 'ddavis' -FirstName 'Dan' -LastName 'Davis' -Password (ConvertTo-SecureString -AsPlainText -Force -String 'Password4') -ResetPasswordOnNextLogon $false
New-Mailbox -Name 'Ed Evans' -Alias 'eevans' -UserPrincipalName 'eevans@corp.domain.com' -SamAccountName 'eevans' -FirstName 'Ed' -LastName 'Evans' -Password (ConvertTo-SecureString -AsPlainText -Force -String 'Password5') -ResetPasswordOnNextLogon $false
New-Mailbox -Name 'Frank Foster' -Alias 'ffoster' -UserPrincipalName 'ffoster@corp.domain.com' -SamAccountName 'ffoster' -FirstName 'Frank' -LastName 'Foster' -Password (ConvertTo-SecureString -AsPlainText -Force -String 'Password6') -ResetPasswordOnNextLogon $false

Copy this and paste it into Exchange Management Shell and you will get six shiny new mailbox users with terrible passwords.