Here's a hackish variation that shows the contents of $error.exception. In my example, the code below shows the error as:
"The object 'vim.VirtualMachine:vm-363' has already been deleted or has not been completely created"
The SRM mgmt page shows protection status as:
"Invalid: Virtual machine 'SERVER01' is no longer protected. VM 'SERVER01' is not replicated by VR. Protected VM deleted."
I'd like to capture that detail message if possible.
$VMWCreds = Get-Credential -Message 'Please provide credentials'
Connect-VIServer -Server 'VC.domain.com' -Protocol 'https' -Credential $VMWCreds
$srmConnection = Connect-SrmServer -SrmServerAddress 'SRM.domain.com' -Protocol 'https' -Credential $VMWCreds
$srmApi = $srmConnection.ExtensionData
$protectionGroups = $srmApi.Protection.ListProtectionGroups()
[System.Collections.ArrayList] $VMProtectionDataAll = @()
$protectionGroups | % {
$protectionGroup = $_
$protectionGroupInfo = $protectionGroup.GetInfo()
# The following command lists the virtual machines associated with a protection group
$protectedVms = $protectionGroup.ListProtectedVms()
# 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
#$protectedVms | % { $_.Vm.UpdateViewData() }
# After the data is populated, use it to generate a report
ForEach ( $tmpVM in $protectedVms ) {
$Error.Clear()
$tmpVM.Vm.UpdateViewData()
If ( $null -ne $Error.Exception ) {
$tmpErrorMsg = ($Error.Exception.Message ).Replace("Exception calling `"UpdateViewData`" with `"0`" argument(s):",'')
} Else {
$tmpErrorMsg = $null
}
[void] $VMProtectionDataAll.Add([PSCustomObject][Ordered] @{
'VMName' = $tmpVM.VmName
'ProtectionGroup' = $protectionGroupInfo.Name
'State' = $tmpVM.State
'PeerState' = $tmpVM.PeerState
'NeedsConfiguration' = $tmpVM.NeedsConfiguration
'Faults' = $tmpVM.Faults
'ErrorDetail' = $tmpErrorMsg
})
}
}
$VMProtectionDataAll | Format-Table -A