Solved

Activate DB on different server if mounted

Posted on 2013-10-22
3
262 Views
Last Modified: 2013-10-27
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.
0
Comment
Question by:SahinBoluk
  • 2
3 Comments
 
LVL 9

Assisted Solution

by:Mahesh Sharma
Mahesh Sharma earned 500 total points
ID: 39591320
If you are using Exchange 2010 with DAG, utilize this script for DAG health check

http://gallery.technet.microsoft.com/office/Exchange-DAG-Replication-d8e99705
0
 
LVL 1

Accepted Solution

by:
SahinBoluk earned 0 total points
ID: 39591623
Thanks,

I got an idea from that script.  My new script looks like this:

$dd2 = get-mailboxserver -Identity "server name" | where-object{$_.AdminDisplayVersion.major -eq "14" -AND $_.DatabaseAvailabilityGroup -ne $null} | Get-MailboxDatabaseCopyStatus -ConnectionStatus | ?{$_.activecopy -eq "True"}
foreach($dd2 in $dd2)
{
      Move-ActiveMailboxDatabase -Identity $dd2.databasename -ActivateOnServer "Server Name" -MountDialOverride 'none' -Confirm:$False
}

This works!  thanks for the "Push" :-).
0
 
LVL 1

Author Closing Comment

by:SahinBoluk
ID: 39603608
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.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data‚Ķ
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates‚Ķ

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question