Solved

Activate DB on different server if mounted

Posted on 2013-10-22
3
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

A brief introduction to what I consider to be the best editor for PowerShell.
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
In this video we show how to create an Address List 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 Organization >> Ad…
To show how to create a transport rule 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 Mail Flow >> Rules tab.:  To cr…

740 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