Get info from Cluster:
1 2 3 4 5 6 |
Get-Cluster Get-ClusterNode Get-ClusterGroup Get-ClusterResource Get-ClusterResource | Select-Object * | Sort-Object cluster,ownernode,name | Out-GridView Get-ClusterResource | Select-Object cluster,ownernode,name, ownergroup,resourcetype, state,characteristics | Sort-Object cluster,ownernode,name | Out-GridView |
Failover general example, you can use Invoke-DbaAgFailover for SQL server:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Invoke-DbaAgFailover dbatools powershell command to failover # Switch the all cluster group to the another node in verbose: # do NOT do in production environment: Get-ClusterGroup | Move-ClusterGroup -verbose # Switch the cluster to the particular Node: # do NOT do in production environment: # Get-ClusterGroup | Move-ClusterGroup -Node ideanodeneve # move one group example: Move-ClusterGroup "Available Storage" Move-ClusterGroup "Cluster Group" |
DBATools makes your life happy, you can find the SQL server instances and you can failover them.
To find all of the SQL instances in a cluster server . To Check AG before and after the failover, and failover the SQL Server AO AG :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# cluster:::::: # (Get-ClusterNode).name | Find-DbaInstance # find SQL server instances in the cluster nodes $SqlServers = (Get-ClusterNode).name | Find-DbaInstance # remote cluster server example: # $SqlServers = (Get-ClusterNode -cluster wvvzrz0020cl).name | Find-DbaInstance $SqlServers $SqlServersOnline = $SqlServers | Where-Object {$_.Availability -eq "Available" } $SqlServersOnline if ($SqlServers.Count -ne $SqlServersOnline.Count) { Write-Host "There are unavailable instances!!!!!" -ForegroundColor Red -BackgroundColor Yellow} # failover GUI Get-DbaAvailabilityGroup -SqlInstance $SqlServersOnline | Out-GridView -Passthru | Invoke-DbaAgFailover # -Confirm:$false -Whatif # instance ellenorzes Get-DbaAgDatabase -SqlInstance $SqlServersOnline | Out-GridView |
if you have to wait a lot for synchronization you can check how many servers are synchronized.
1 2 3 4 5 6 7 8 9 |
$SqlServersOnline = (Get-ClusterNode).name | Find-DbaInstance | Where-Object {$_.Availability -eq "Available" } do { Write-Host; Write-Host "*********************************************************************************************";` $Databases= Get-DbaAgDatabase -SqlInstance $SqlServersOnline; Start-Sleep -Seconds 1.0 ; ` Start-Sleep -Seconds 0.5 ; ` Write-Host -NoNewline (Get-Cluster).Name "has" $Databases.Count " AG databases. " ; ` Write-Host ($Databases | Where-Object {$_.SynchronizationState -eq "Synchronized" }).count "databases are synchronized at" (Get-Date).ToString(); ` Write-Host -NoNewline "Out of Synchron:" ($Databases | Where-Object {$_.SynchronizationState -ne "Synchronized" }) | Select-Object Name ; ` } ` while ( ($Databases | Where-Object {$_.SynchronizationState -ne "Synchronized" }).count -ne 0 ); |