Forum Discussion
Automation of Exchange server Patching
Hi I am trying to setup a Script to automate patching of Exchange 2016 servers and I need to get the script to check if any if the other exchange server is in Maintenance Mode before continuing to place the first server into maintenance mode to allow me to install the updates and reboot the server.
if I run the command "Get-databaseavailabilitygroup -status | fl ServersInMaintenance" it gives the result "ServersInMaintenance : {}" what I need to do it get a command to check that this result is this then continue but I cannot find anyway to interpret this result have tried
$Maint = Get-databaseavailabilitygroup -status | fl ServersInMaintenance
If ($Maint -contains {} ) { Write-Host "No Servers in Maintenace Mode"}
But this doesn't work any help would be gratefully received
10 Replies
- You could do like this
$Maint = Get-DatabaseAvailabilityGroup -status
If ($Maint.ServersInMaintenance.count -eq 0 ) { Write-Host "No Servers in Maintenance Mode"}
This if you only have one DAG.
If you have more than one you will need to iterate between them- SteveCoxBrass ContributorThanks that works perfectly now need to check cluster node Status so if I run
"Get-ClusterNode -Name Exchange1 | FL State"
I Get "State : Up" as an output but if I try
"$cluster = Get-ClusterNode -Name Exchange1 | FL State
If ($cluster.state -eq "Up") { Write-Host "Cluster is Up"}
I get nothing- Have to boot up my Exchange lab to check, however, be careful while assigning Format-List output to a variable, that should be used only to output to screen.
So it would be better to:
$cluster = Get-ClusterNode -Name Exchange1
If ($cluster.state -eq "Up") { Write-Host "Cluster is Up"}