How to get values from a VM using PowerCLI

Hello,

The following line of code returns a lot of values (I’ve only copied a few in the interest of brevity):

PS C:\PS> $myVM.ExtensionData.Config.ExtraConfig

Key                                   Value                                                           
---                                   -----                                                           
hbr_filter.configGen                  5                                                               
hbr_filter.gid                        GID-9999999-9999-9999-9999-99999999                        
hbr_filter.destination                xx.xxx.xx.xxx                                                     
hbr_filter.port                       31031                                                           
hbr_filter.rpo                        480                                                             

The value I’m interested in extracting is the hbr_filter.rpo. However, the following won’t do:

PS C:\PS> $myVM.ExtensionData.Config.ExtraConfig.hbr_filter.rpo

Moreover, I’m interested in building an automated report for SRM replication metrics that shows Last Sync Duration, Last Sync Size, Lag Time, RPO, and Current RPO Violation. Much like the GUI based SRM report shows.

Any code samples or suggestions greatly appreciated.

Hello, I hope you are doing well. ‘ExtraConfig’ is a hashtable. You can access values of keys with brackets. In your case the following line should work to access the value of hbr_filter.rpo

$myVM.ExtensionData.Config.ExtraConfig['hbr_filter.rpo']

Hi.

Appreciate the quick reply. I tried your suggestion but it returns an empty value.

$RPO = $myVM.ExtensionData.Config.ExtraConfig['hbr_filter.rpo']
Write-Host $RPO

PS c:\scripts> 

Using double quotes does not work either. I’m not sure why. But, since you pointed out that it’s a hash table, looping through the keys looking for the right value works.

$myVM.ExtensionData.Config.ExtraConfig |
 % {
   If ($_.Key -eq "hbr_filter.rpo") {
            $RPO = $_.Value
        }
    }
Write-Host $RPO

PS c:\scripts> 480

However, I hate introducing yet another loop just to get one value. Looking for a way to get that value in a more direct fashion.

Best regards.

Ahhh so it’s not a hashtable. Apologies, it’s a collection of objects that values can be access by keys. Hopefully somebody else has a better solution. With powershell you could also is Where-Object but again I’m sure there is some iterative process happening in the background:
$RPO = ($myVM.ExtensionData.Config.ExtraConfig | Where-Object { $_.Key -eq 'hbr_filter.rpo' }).Value

After some more digging, I found an easier method:

$RPO = $myVM.ExtensionData.Config.ExtraConfig.RepInfo.Rpo

Returns the correct value.

Thanks for your suggestions.

That way is very straight forward. Nice stuff!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.