Get-SRRecoveryPlan and Get-SRProtectionGroup, which are not PowerCLI cmdlets; it now uses Connect-SrmServer and the SRM API that ships with PowerCLI. For SRM 8.7 and later you can also use the VMware.Sdk.Srm module.To validate any failures on VMware Site Recovery Manager (SRM), you can use PowerShell along with VMware PowerCLI to check the status of the recovery plans, protection groups, and the overall SRM environment. Here’s a PowerShell script that helps you validate SRM failures:
# PowerCLI (VCF.PowerCLI or VMware.PowerCLI) includes Connect-SrmServer for the SRM API
$protectedSiteServer = '<PROTECTED_SITE_VCENTER_FQDN>'
$recoverySiteServer = '<RECOVERY_SITE_VCENTER_FQDN>'
$protectedSiteCredential = Get-Credential -Message 'Credentials for the protected site vCenter Server'
$recoverySiteCredential = Get-Credential -Message 'Credentials for the recovery site vCenter Server'
Connect-VIServer -Server $protectedSiteServer -Credential $protectedSiteCredential -ErrorAction Stop | Out-Null
Connect-VIServer -Server $recoverySiteServer -Credential $recoverySiteCredential -ErrorAction Stop | Out-Null
# Log in to the SRM server paired with the protected site vCenter (and to the remote site)
$srm = Connect-SrmServer -Server $protectedSiteServer -Credential $protectedSiteCredential `
-RemoteCredential $recoverySiteCredential -ErrorAction Stop
$srmApi = $srm.ExtensionData
# Function to Check Recovery Plan Status
function Get-RecoveryPlanStatus {
param ([Parameter(Mandatory = $true)] $RecoveryPlan)
$info = $RecoveryPlan.GetInfo()
[PSCustomObject]@{
Type = 'RecoveryPlan'
Name = $info.Name
State = $info.State # e.g. Ready, Running, NeedsCleanup, NeedsReprotect, Incomplete
Issue = $info.State -notin 'Ready', 'Protecting'
}
}
# Function to Check Protection Group Status
function Get-ProtectionGroupStatus {
param ([Parameter(Mandatory = $true)] $ProtectionGroup)
$info = $ProtectionGroup.GetInfo()
$state = $ProtectionGroup.GetProtectionState()
$vms = $ProtectionGroup.ListProtectedVms()
$bad = @($vms | Where-Object { $_.NeedsConfiguration -or $_.State -ne 'Ready' })
[PSCustomObject]@{
Type = 'ProtectionGroup'
Name = $info.Name
State = "$state, $(@($vms).Count) VMs, $($bad.Count) need attention"
Issue = $bad.Count -gt 0
}
}
# Main Script
$results = foreach ($plan in $srmApi.Recovery.ListPlans()) { Get-RecoveryPlanStatus -RecoveryPlan $plan }
$results += foreach ($pg in $srmApi.Protection.ListProtectionGroups()) { Get-ProtectionGroupStatus -ProtectionGroup $pg }
$results | Format-Table Type, Name, State, Issue -AutoSize
if ($results | Where-Object Issue) { Write-Warning 'SRM objects need attention - see the table above.' }
# Disconnect
Disconnect-SrmServer -Server $srm -Confirm:$false
Disconnect-VIServer -Server $protectedSiteServer, $recoverySiteServer -Confirm:$false
Save the above script in a .ps1 file and run it with PowerShell. The script will prompt you to enter the credentials for the protected site and recovery site vCenter Servers. It will then connect to both vCenter Servers and to SRM, retrieve the state of all recovery plans and protection groups, and display the results in the PowerShell console.
The script will check the state of each recovery plan (for example Ready, NeedsCleanup after a test, or NeedsReprotect after a failover) and, for each protection group, its protection state and any protected VMs that need configuration. Anything that is not ready is flagged in the Issue column. Replace the values in <ANGLE_BRACKETS> with your own.
This script helps you quickly validate failures in your SRM environment and can be scheduled to run periodically for proactive monitoring. You can also integrate it into your monitoring systems to receive alerts in case of any issues with SRM recovery plans and protection groups. For related procedures see performing a test failover with SRM.
Leave a Reply