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
Try the following code see if it helps
Download and install SRM PowerCLI Cmdlets from https://developer.vmware.com/samples/2512/srm-powercli-cmdlets
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
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
Afaik the ListPlans method has no parameters
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
could you please help me, how to get the VM details from Recovery Plan.
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
Try the following code see if it helps
Download and install SRM PowerCLI Cmdlets from https://developer.vmware.com/samples/2512/srm-powercli-cmdlets
Thank you very much for your help. I was able to import the module and run using powercli 12.x 🙂