Activate DB on different server if mounted
Posted on 2013-10-22
I'm trying to write a script that will check to see if a DB is mounted on a specific server, and if it is mounted, activate it on a different server. Below is what I have so far, but not working:
$dd1=Get-MailboxDatabaseCopyStatus -Server xxxx
if ($db1.Status -eq "mounted")
Move-ActiveMailboxDatabase -ActivateOnServer yyyy -MountDialOverride 'none' -Confirm:$False
The error that I am getting is :
Cannot index into a null array.
At C:\DBSwitch.ps1:2 char:10
+ if ($db1[ <<<< 0].Status -eq "mounted")
+ CategoryInfo : InvalidOperation: (0:Int32) , RuntimeException
+ FullyQualifiedErrorId : NullArray
I'm thinking that it doesn't like my variable declaration.
I can do it another way, but that would require me to "manually" enter each DB name. This is not what I am looking for as I need to make this a scheduled task.