VMware Cloud Community
piercj2
Enthusiast
Enthusiast

PowerCLI returning incorrect data via SRM API

Hi,

The following script is being used to provide a daily report on the state of SRM Protection Groups and, the VM's they protect.

Connect-viserver xxxxxxxxxxx
$srm = Connect-SrmServer #|out-null

$srmApi = $srm.ExtensionData
$protectionGroups = $srmApi.Protection.ListProtectionGroups()

$protectionGroups | % {
    $protectionGroup = $_
   
    $protectionGroupInfo = $protectionGroup.GetInfo()
    $protectionGroupState = $protectionGroup.GetProtectionState()
    $recoveryPlanName = $protectionGroup.ListRecoveryPlans().GetInfo().Name
   
    # The following command lists the virtual machines associated with a protection group
    $protectedVms = $protectionGroup.ListProtectedVms()
    $protectedVms | % { $_.Vm.UpdateViewData() }
    $protectedVms | %{
        $output = "" | select PgName, PgState, RpName, VmName, VmState
        $output.PgName = $protectionGroupInfo.Name
        $output.PgState = $protectionGroupState
        $output.RpName = $recoveryPlanName
        $output.VmName = $_.Vm.Name
        $output.VmState = $protectedVms.State
        $output
    }
} | Format-Table @{Label="Protection group name"; Expression={$_.PgName}},
    @{Label="Protection group state"; Expression={$_.PgState}},
    @{Label="RecoveryPlan Name"; Expression={$_.RpName}},
    @{Label="VM Name"; Expression={$_.VmName} },
    @{Label="VM State"; Expression={$_.VmState}} # | sort "Protection Group Name"

In testing, I've noticed two issues with the results provided by the above.

  1. The Protection Group State (PgState) returned is either
    • Ready
    • Shadowing

           Even if I intentionally break the Protection by adding a CD-Drive or moving a .vmdk to non-replicated storage, the returned State is Ready or Shadowing despite the Web Client showing the            Status of Not Configured

  2. The VM State (VmState) returned is

    • Ready
    • Shadowing

          Again, if I add a CD-Drive or change .vmdk locations, Returned State is Ready or, Shadowing, despite the Web Client showing a Protection Status of Device not found, CD/DVD Drive x

Am I looking at the correct properties in the above to return the information I'm trying to get back ?

A Summary of my environment is

  • SRM Version 5.8.1
  • PowerShell Version 5.0.10586.117
  • PowerCLI Version 6.5
  • SRM API Version 3.0

Thanks

Tags (2)
0 Kudos
3 Replies
meda1983
Enthusiast
Enthusiast

i think i have seen this before or something similar.  it makes a huge difference on some API calls based on which srm server you connected.

are you connecting to the srm server on the production site or the recovery site?

try below where u connect to prod vcenter and use the remoteuser option to get the details .  I have a script that i used to export all config from srm on a day to day basis. i can share that if you want.

connect-viserver -server prodvcenter -user username -Password password -warningaction:SilentlyContinue |out-null

$srm= connect-srmserver -remoteuser

0 Kudos
piercj2
Enthusiast
Enthusiast

Thanks for the reply.

I connected using the following

connect-viserver -server prodvcenter -user username -Password password -warningaction:SilentlyContinue |out-null

$srm= connect-srmserver -remotecredential

Unfortunately I get the same results, i.e. a Protection Group that the Web Client shows a Protection Status of Not Configured, PowerCLI returns a Status of Ready.

Same for the VM, "Protection Status" in the Web Client is "Device Not Found: CD/DVD" but, powerCLI returns a Status of Ready

I would love to see your Script for exporting the SRM Config, if you can share that.

Regards,

Jason

0 Kudos
meda1983
Enthusiast
Enthusiast

check out this link .  i have that script in there that exports all the SRM config.  sorry for the late response

https://www.linkedin.com/pulse/powershell-scripts-recover-mission-critical-you-do-have-vamshi-meda

0 Kudos