The current project I'm working on required me to create a large number of mailbox-enabled user accounts in an Exchange 2007 organization. When you're using Exchange 2007, you need to provision your accounts with Exchange 2007's tools, and the Exchange Management Shell (EMS) makes creating mailboxes quick and easy. Here's the script I used:
$pw = Read-Host "Enter password:" -AsSecureString
get-content mailboxes.txt | foreach {
$umb=@{}
$umb.acc, $umb.fn, $umb.ln = $_.split()
$upn = $umb.acc + '@contoso.com'
$wn = $umb.fn + ' ' + $umb.ln
New-Mailbox `
-Alias $umb.acc `
-SamAccountName $umb.acc `
-UserPrincipalName $upn `
-Name $wn -FirstName $umb.fn `
-LastName $umb.ln `
-OrganizationalUnit 'contoso.com/Users' `
-Password $pw `
-ResetPasswordOnNextLogon $false `
-Database 'MBX01\First Storage Group\Mailbox Database'
}
This approach uses the Get-Content cmdlet and a foreach loop to break out each field into a separate variable using the split operator.
It turns out, though, there's an easier way to do it: use the Import-CSV cmdlet. Bharat Suneja shows you how to use it over on his blog. Man, I wish I'd known about that.
Powershell (despite abandoning the cool name of Monad) rocks.