Folks:
I'll admit I am not a powercli guru, and utilize other people's published code to get the job done. In this case, it's a result in trying to find a "canned" report that would dump the VM/Protection Group/Recovery plan into a report that can be added to our audited DR plan. For the life of me I don't understand why this isn't already in the product, but that be as it may. The below code works but I happen to have two recovery "realms" - I protect our HQ Cluster/Vcenter1 with a recovery plan in our Colo Cluster/Vcenter2, and vice versa I protect our Colo Cluster/Vcenter2 with a recovery plan in HQ Cluster/Vcenter1. Vcenters in in embedded link mode, SRM 8.2 Vcenter 6.7U3.
The crux of the problem is "$srmApi.Protection.ListProtectionGroups" list all of the protection groups (both HQ and Colo) which is good, but "$protectionGroup.ListAssociatedVms()" only sees VM's in my HQ Vcenter. The Colo VM's error out-
Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.VirtualMachine:vm-355' has already been deleted or has not been completely created"
At C:\Temp\srm_report.ps1:13 char:16
+ $vms | % { $_.UpdateViewData() }
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
I played with the connect statement to use the Colo Vcenter as the connection point, but same result, the Colo VM's are not detected. This was not what I was expecting I figured I'd be missing the HQ VM's.
$credential = Get-Credential
Connect-VIServer -Server 10.10.10.10 -Credential $credential
Connect-SrmServer -port 443 -Credential $credential -RemoteCredential $credential
So I'm at a loss to explain how to get the "$protectionGroup.ListAssociatedVms()" to reference both Vcenters. What do you think?
srmApi = $srmConnection.ExtensionData
$protectionGroups = $srmApi.Protection.ListProtectionGroups()
#Generate a report of the virtual machines associated with all protection groups.
$protectionGroups | % {
$protectionGroup = $_
$protectionGroupInfo = $protectionGroup.GetInfo()
# The following command lists the virtual machines associated with a protection group
$vms = $protectionGroup.ListAssociatedVms()
# The result of the above call is an array of references to the virtual machines at the vSphere API
# To populate the data from the vSphere connection, call the UpdateViewData method on each virtual machine view object
$vms | % { $_.UpdateViewData() }
# After the data is populated, use it to generate a report
$vms | %{
$output = "" | select VmName, PgName
$output.VmName = $_.Name
$output.PgName = $protectionGroupInfo.Name
$output
}
} | Format-Table @{Label="VM Name"; Expression={$_.VmName} }, @{Label="Protection group name"; Expression={$_.PgName} }