NSCLIENT - check_vm_repl.ps1

try{ $vms = Get-VM | Select-Object -Property VMName,VMId,Generation,Path,State,Status,ReplicationMode,ReplicationHealth $replications = @($vms | Where {$.ReplicationMode -in @(“Primary”,”Replica”)} ) $healthy = @($vms | Where {$.ReplicationHealth -eq “Normal”} ) $warning = @($vms | Where {$.ReplicationHealth -eq “Warning”} ) $critical = @($vms | Where {$.ReplicationHealth -eq “Critical”} ) } catch{ Write-Host $_.Exception.Message exit 3 } finally{ If(@($critical).count -gt 0){ Write-Host “$($critical.count) VMs in critical state: $(($critical | select -ExpandProperty VMName) -join ",”)” exit 2 } ElseIf(@($warning).count -gt 0){ Write-Host “$($warning.count) VMs in warning state: $(($warning | select -ExpandProperty VMName) -join ",”)” exit 1 } ElseIf(@($healthy).count -eq @($replications).count){ Write-Host “$($healthy.count) VMs in healthy state. $($replications.count) VMs replicating. $($vms.count) VMs total.” exit 0 } Else{ Write-Host “Unknown error” exit 3 } }