VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Unable to list VM details from SRM Recovery Groups

Hi,

I am trying to list VMs details from SRM Recovery Group, and I am getting the below error.

Please help!!

 

# Connect to vCenter Server and SRM Server
connect-viserver "Myvcenter"


# Define API variable
$SrmConnection = Connect-SrmServer
$SrmApi = $SrmConnection.ExtensionData

# Specify the name of the recovery plan
$recoveryPlanName = "Mgmt_Recovery_plan1"

# Get the recovery plan by name
$recoveryPlan = $SrmApi.Recovery.ListPlans().GetInfo() | Where-Object {$_.Name -eq $recoveryPlanName}

if ($recoveryPlan -eq $null) {
Write-Host "Recovery plan '$recoveryPlanName' not found."
} else {
# List VMs in the recovery plan
$vmList = $SrmApi.Recovery.ListPlanItems($recoveryPlan.PlanId).GetInfo() | ForEach-Object {
$planItem = $_
$vmId = $planItem.GetLocation().VmId
$vm = Get-VM -Id $vmId
$recoveryStatus = $planItem.GetState().RecoveryStatus
$protectionGroup = $SrmApi.Protection.GetProtectionGroup($planItem.ProtectionGroupId).GetInfo()

[PSCustomObject]@{
VMName = $vm.Name
RecoveryStatus = $recoveryStatus
ProtectionGroupName = $protectionGroup.Name
Priority = $planItem.Priority
FinalPowerState = $planItem.FinalPowerState
}
}

# Display VM information
$vmList | Format-Table -AutoSize
}

# Disconnect from vCenter Server and SRM Server
Disconnect-VIServer -Server * -Confirm:$false
Disconnect-SrmServer -Server * -Confirm:$false

 

Error

Method invocation failed because [VMware.VimAutomation.Srm.Views.SrmRecovery] does not contain a method named 'ListPlanItems'.
At D:\List_VMs_In_A_Recovery_Group.ps1:19 char:5
+ $vmList = $SrmApi.Recovery.ListPlanItems($recoveryPlan.PlanId).Ge ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

 

0 Kudos
1 Solution

Accepted Solutions
wetnose88
Enthusiast
Enthusiast
Jump to solution

Try the following code see if it helps

wetnose88_0-1687969746078.png

 

Download and install SRM PowerCLI Cmdlets from https://developer.vmware.com/samples/2512/srm-powercli-cmdlets

 

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

Where did you find that ListPlanItems method?
It doesn't exist, which is exactly what the error is telling you.
See the SRM API reference.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

After I made the changes referring to API guide, still I am getting below error

Cannot find an overload for "ListPlans" and the argument count: "1".
At D:\List_VMs_In_A_Recovery_Group.ps1:19 char:1
+ $vmList = $SrmApi.Recovery.ListPlans($recoveryPlan.PlanId).GetInfo() ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest

 

Tags (1)
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik the ListPlans method has no parameters


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

could you please help me, how to get the VM details from Recovery Plan. 

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I do not use SRM, so I can't really test anything.
Did you already have a go with the  ?
There are a number of cmdlets in there that might help.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
wetnose88
Enthusiast
Enthusiast
Jump to solution

Try the following code see if it helps

wetnose88_0-1687969746078.png

 

Download and install SRM PowerCLI Cmdlets from https://developer.vmware.com/samples/2512/srm-powercli-cmdlets

 

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you very much for your help. I was able to import the module and run using powercli 12.x 🙂

 

0 Kudos