Activate SCR Target via EMS script
March 15, 2009 · Filed Under Exchange Server 2007, Powershell | 525 views
If you’ve got SCR installed and are using the Database Portability model described in “Standby Continuous Replication: Database Portability“, here’s a useful Exchange Management Shell that scripts the entire activation process. Just change all of the noted fields to match your source and target servers and even add additional storage groups/databases to the script if you like.
Be sure to triple check your entries and TEST IN A LAB ENVIRONMENT before unleashing this production!
Activate-SCRTarget.zip (1.6 KiB, 663 hits)
Comments
2 Responses to “Activate SCR Target via EMS script”
Leave a Reply











































Can I get some feedback on this scipt for SCR failover? It’s intended to be run from the Standby server.
$standbymachine = [Environment]::machinename
$recovery_dbs = @()
$prod_sgs = Get-StorageGroup |? {$_.standbymachines.count -ge 1}
foreach ($prod_sg in $prod_sgs){
foreach ($prod_standby in $prod_sg.standbymachines){
if ($prod_standby.nodename.split(”.”)[0] -eq $standbymachine){
Write-Host “`nFound $($prod_sg.identity) targeted to this server:`n”
$prod_db = Get-MailboxDatabase |? {$_.storagegroup -eq $prod_sg.identity}
$recovery_db = “” | select sg_id,db_id,systemfolderpath,logfolderpath,logfileprefix,edbfilepath
$recovery_db.sg_id = $prod_sg.identity
$recovery_db.db_id = $prod_db.identity
$recovery_db.systemfolderpath = $prod_sg.systemfolderpath
$recovery_db.logfolderpath = $prod_sg.logfolderpath
$recovery_db.logfileprefix = $prod_sg.logfileprefix
$recovery_db.edbfilepath = $prod_db.edbfilepath
}
}
$recovery_dbs += $recovery_db
}
foreach ($recovery_db in $recovery_dbs){
$failover_sgname = $recovery_db.db_id.tostring().split(”\”)[1] + “DR”
$failover_dbname = $recovery_db.db_id.tostring().split(”\”)[2] + “DR”
$failover_sg = $standbymachine + “\” + $failover_sgname
$failover_db = $failover_sg + “\” + $failover_dbname
if (!(test-path “c:\exdr_temp”)){New-Item “c:\exdr_temp” -type d}
New-StorageGroup -Name $failover_dbname -Server $standbymachine -logfolderpath c:\exdr_temp -systemfolderpath c:\exdr_temp
New-mailboxdatabase -Name $failover_dbname -StorageGroup $failover_sg -EdbFilePath c:\exdr_temp\temp.edb
Dismount-Database $failover_db
Remove-Item c:\exdr_temp\*.*
Restore-StorageGroupCopy $recovery_db.sg_id -standbymachine $standbymachine -force
Move-StorageGroupPath $failover_sg -SystemFolderPath $recovery_db.systemfolderpath -logfolderpath $recovery_db.logfolderpath -configurationonly
Set-MailboxDatabase $failover_db -AllowFileRestore:$true
Mount-Database $failover_db
if (!($(get-mailboxdatabase $failover_db -status).mounted)){
eseutil /r $recovery_db.logfileprefix /l $recovery_db.logfolderpath /s $recovery_db.systemfolderpath /d $recovery_db.edbfilepath
Mount-Database $failover_db
}
Get-Mailbox -Database $recovery_db.db_id |?{$_.objectclass -notmatch “(systemattendantmailbox|exoledbsystemmailbox)”} |Move-Mailbox -TargetDatabase $failover_db -ConfigurationOnly
}
Rob, like we discussed via email, the script looks great with the few suggestions I mentioned. Very portable unlike mine with things being hardcoded.