Link to home
Start Free TrialLog in
Avatar of SahinBoluk
SahinBoluk

asked on

Activate DB on different server if mounted

Hi,

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[0].Status -eq "mounted")
{
      Move-ActiveMailboxDatabase -ActivateOnServer yyyy -MountDialOverride 'none' -Confirm:$False
}
else
{
exit
}

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.
SOLUTION
Avatar of Mahesh Sharma
Mahesh Sharma
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SahinBoluk
SahinBoluk

ASKER

Mks_ directed me to a script which I can use to guide me on creating a working script.  I have copied the script that works for anyone else that needs it.