Wednesday, September 5, 2012

Exchange Online coexistence with generic SMTP mail

Recently we moved a client from MDaemon to Exchange Online. Because the individual user's setups were complex affairs, with lots of users attached and lots of PSTs, we wanted to move them individually, rather than trying to do it all in one hit.

The approach suggested by Microsoft is to forward mail to the .onmicrosoft.com accounts as they are created. However, this doesn't handle return mail from the cloud to the onpremise server.

The way I solved it was this:

1. Create the organisation account customer.onmicrosoft.com in the Exchange cloud, specify it as shared, add customer.com.
2. Set up the onpremise mail server with an alias domain of smtp.customer.com. As there was already an A record for this there was no need to change any DNS.
3. Create all accounts in the cloud, specifying they forward to username@smtp.customer.com. Set customer.com as default sending address.
4. As accounts are moved to the cloud, set a forward from their account on the onpremise server to username@customer.onmicrosoft.com. Delete the forward from the exchange cloud account.

In this way we could move individual mailboxes without compromising their ability to email everyone else in the organisation. Once the migration is complete, we can change the MX records to point to the cloud and remove the onpremise server.


Tuesday, February 14, 2012

Mass creating users and exchange mailboxes from a CSV using Powershell

During a swing migration to a new domain I had to quickly create a ton of users with their mailboxes to enable importing their PST files.

I found this script somewhere on the net but it had some bugs so I cleaned it up.
Note that the CSV as its first line needs labels for each column like:
fn,ln,dispname,alias,upn

and UPN is the users email address.


Function ReadCSV{
 Param([string]$fileName)
 $users = Import-Csv $fileName
 foreach ($user in $users){
 $ht  = @{
 'givenName'=$user.fn
 'sn'=$user.ln
 'displayName'=$user.dispname
 'alias'=$user.alias
 'samAccountName'=$user.alias
 'userPrincipalName' = $user.upn
 'database' = 'Mailbox Database'
 'organizationalUnit' = 'OU=Company,OU=Users,OU=Yoyodyne,DC=yoyodyne,DC=local'
 'name' = ($user.fn +" "+$user.ln)
 }
 Write-Output $ht
 }


}
Function CreateUser{
 Param($userInfo)
 $secureString = ConvertTo-SecureString "User!123" -AsPlainText –Force
 New-Mailbox  -Name $userInfo['name' ]`
 -Alias $userInfo['alias'] -UserPrincipalName $userInfo['userPrincipalName'] `
 -SamAccountName $userInfo['alias'] -Database $userInfo['Database']`
 -FirstName $userInfo['givenName'] -LastName $userInfo['sn'] `
 -OrganizationalUnit $userinfo['organizationalUnit']`
 -DisplayName $userInfo['DISPLAYNAME'] -Password $secureString -ResetPasswordOnNextLogon $false


}


Function CreateMailbox{
 PROCESS
 {
 CreateUser $_
 }
}


 ReadCSV users.csv | CreateMailbox