I have a PSCustomObject which has list of sub-objects like this:
vmssSystemUpdatesMonitoringEffect : @{type=String; metadata=; allowedValues=System.Object[]; defaultValue=AuditIfNotExists} vmssEndpointProtectionMonitoringEffect : @{type=String; metadata=; allowedValues=System.Object[]; defaultValue=AuditIfNotExists} vmssOsVulnerabilitiesMonitoringEffect : @{type=String; metadata=; allowedValues=System.Object[]; defaultValue=AuditIfNotExists} systemUpdatesMonitoringEffect : @{type=String; metadata=; allowedValues=System.Object[]; defaultValue=AuditIfNotExists} systemConfigurationsMonitoringEffect : @{type=String; metadata=; allowedValues=System.Object[]; defaultValue=AuditIfNotExists} etc.
Part of the object as JSON:
{ "vmssSystemUpdatesMonitoringEffect": { "type": "String", "metadata": { "displayName": "System updates on virtual machine scale sets should be installed", "description": "Enable or disable virtual machine scale sets reporting of system updates" }, "allowedValues": [ "AuditIfNotExists", "Disabled" ], "defaultValue": "AuditIfNotExists" }, "vmssEndpointProtectionMonitoringEffect": { "type": "String", "metadata": { "displayName": "Endpoint protection solution should be installed on virtual machine scale sets", "description": "Enable or disable virtual machine scale sets endpoint protection monitoring" }, "allowedValues": [ "AuditIfNotExists", "Disabled" ], "defaultValue": "AuditIfNotExists" }, "vmssOsVulnerabilitiesMonitoringEffect": { "type": "String", "metadata": { "displayName": "Vulnerabilities in security configuration on your virtual machine scale sets should be remediated", "description": "Enable or disable virtual machine scale sets OS vulnerabilities monitoring" }, "allowedValues": [ "AuditIfNotExists", "Disabled" ], "defaultValue": "AuditIfNotExists" } } Keys I get to array with
$Keys = $Hash | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name I can get the keys into array and iterate them but I cannot access properties by giving the key with variable:
foreach ($key in $Keys) { Write-Host "key" $key $data = $KeyValue.$key } Result: key aadAuthenticationInServiceFabricMonitoringEffect
and data empty
However, this works:
$KeyValue.vmssSystemUpdatesMonitoringEffect And this:
$key= "aadAuthenticationInServiceFabricMonitoringEffect" $KeyValue.$key How could I get this working with variable?

$json.vmssEndpointProtectionMonitoringEffect.psobject.Properties.nameafter importing your json, it work... If you do a.gettype()onaadAuthenticationInServiceFabricMonitoringEffect, what's the object type ? (since the one you have problems with is not in the json sample)Get-Memberto see if it's properties could be somewhat not of typeNoteProperty. Also make sure that the path toaadAuthenticationInServiceFabricMonitoringEffectis good as if you do$Keyvalue.aadAuthenticationInServiceFabricMonitoringEffectand the actual path is something else, for instance :$Keyvalue.Me.aadAuthenticationInServiceFabricMonitoringEffectthen that would explain why you do not get data.