I've been creating mailboxes for some of our existing users who don't have their own mailbox so I've written a little script to make things easier for myself. Relevant extract below.
$exchange = New-PSSession -ConfigurationName microsoft.exchange -ConnectionUri http://exchangesvr/powershell
$newMailbox = Invoke-Command -Session $exchange -ScriptBlock{param ($mailbox,$alias)Enable-Mailbox -Identity $mailbox -Database "userdb" -Alias $alias} -ArgumentList $user, $first_last
$mailMessageParameters = @{
From = "helpdesk@company"
To = $email_address
Subject = "Welcome to your new Mailbox!"
SmtpServer = "exchangesvr"
Body = $emailBody
}
Send-MailMessage @mailMessageParameters -BodyAsHtml
Trouble with this though is half the time I get a bounceback when sending the mail - I'm assuming the issue is the lookup for the address is happening on a different server in our exchange cluster where the mailbox hasn't replicated to yet. I've tried specifying both a cas server and a hub transport for the creation/mailing, but it doesn't seem to make a difference. I was going to just add a static sleep before sending the mail but I was hoping there is a 'smarter' way of doing this.