Hello, Good Morning!
I've been working with Exchange 2010 and powershell for a few months now have a good foundation knowledge on the subject but i'm still learning powershell.
We have a DAG with 10 databases and each database has 3 members, from time to time they fail over to second or third nodes and i can login and manually move them back or use a powershell to identify the ones that aren't where they need to be and then run a second command to move them back again. I'm trying to combine the 2 so if its not on its prefered server then it moves it back (this is part of a bigger script to confirm the mailboxdatabasecopystatus is ok first.
Here is my first part of the code to find out if its not on the primary server.
Get-MailboxDatabase | Where {$_.Recovery -eq $False} | Sort Name | ForEach { $db = $_.Name $curServer = $_.Server.Name $ownServer = $_.ActivationPreference | ? {$_.Value -eq 1} If ($curServer -ne $ownServer.Key.Name) { Write-Host "$db on $curServer should be on $($ownServer.Key.Name)!" -ForegroundColor Red } }
I then tried to add the move-activemaiboxdatabase
Get-MailboxDatabase | Where {$_.Recovery -eq $False} | Sort Name | ForEach { $db = $_.Name $curServer = $_.Server.Name $ownServer = $_.ActivationPreference | ? {$_.Value -eq 1} If ($curServer -ne $ownServer.Key.Name) { Write-Host "$db on $curServer should be on $($ownServer.Key.Name)!" -ForegroundColor Red Move-ActiveMailboxDatabase -identity $db -ActivateOnServer $ownServer -confirm get-mailboxdatabase -identity $db | ft Name, Server $db = $_.Name $curServer = $_.Server.Name Write-Host "$db is now on $curServer" -ForegroundColor Green } }
This fails as $ownServer is [Server, 1] i need it to just be the server name, is there an easier way to do this or will i just need to do some string manipulation on the $ownServer value to get it in to the cmdlet?
Thanks for any help
Mike
.: Lister :.