Thursday, April 8, 2010

Database failover on Exchange 2010

When a Database fail-over occurs in a DAG, the database will remain active on the new active node, until this node fails, or "ActiveServer", on the database, is changed manually.
This is a problem for me, on site servers. If they are rebooted, it is important, that the database becomes active on the site server, when it's up again.

Therefore, I have made a script, that I run from "Scheduled tasks"
Remember, that the user, that executes the script, must be member of "organization administrators"(or corresponding exchange group), local admin group for the server and have "log on as a batch job rights"

Make a scheduled task, that runs "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe c:\PSscripts\MoveDB.ps1"

I have set the script to run every morning, but could also be a startup script, but the there should be put a delay in the script.

The Powershell script, will be run from the powershell.exe, that does not know the Exchange PS commands, so I start the script with adding the exchange snapin.

The 2 liner script:
Add-PSSnapin microsoft.Exchange.Management.PowerShell.E2010
Get-MailboxDatabase DBname | where { $_.server -notlike "siteserver-servername" } | Move-ActiveMailboxDatabase -ActivateOnServer 'siteserver-servername' -MountDialOverride 'None' -Confirm:$false -TerminateOnWarning | fl >> "C:\PSscripts\MoveDB2.LOG"