I'm using az vm list-skus -l australiasoutheast | convertfrom-json to populate a variable (lets call it $skus) so I can use it in a PS script. When $skus is populated, it's contents look like:
apiVersions :
capabilities : {@{name=MaxResourceVolumeMB; value=256000}, @{name=OSVhdSizeMB; value=1047552}, @{name=vCPUs; value=8}, @{name=MemoryPreservingMaintenanceSupported; value=False}…}
capacity :
costs :
family : standardMSFamily
kind :
locationInfo : {@{location=australiasoutheast; zoneDetails=System.Object[]; zones=System.Object[]}}
locations : {australiasoutheast}
name : Standard_M8-4ms
resourceType : virtualMachines
restrictions : {}
size : M8-4ms
tier : Standard
The capabilities and locatioinfo objects in the variable look like hashtables.
I can do $skus | select name, capabilities which outputs:
name capabilities
---- ------------
Aligned {@{name=MaximumPlatformFaultDomainCount; value=2}}
Classic {@{name=MaximumPlatformFaultDomainCount; value=3}}
Premium_LRS {@{name=MaxSizeGiB; value=4}, @{name=MinSizeGiB; value=0}, @{name=MaxIOps; value=120}, @{name=MinIOps; value=120}…}
Premium_LRS {@{name=MaxSizeGiB; value=128}, @{name=MinSizeGiB; value=64}, @{name=MaxIOps; value=500}, @{name=MinIOps; value=500}…}
Premium_LRS {@{name=MaxSizeGiB; value=256}, @{name=MinSizeGiB; value=128}, @{name=MaxIOps; value=1100}, @{name=MinIOps; value=1100}…}
How can I get to and extract the data I need from those hashtables?
I tried the usual select-object to try and get to it, but I can only get as far as the capabilities object, but I cannot reference anything inside that.
To retrieve all capabilities from a hash table, use
Select-Objectto print the specific value from the capabilities parameter.Here is the PowerShell script to reference the value from capabilities parameter.
Output:
To display all values within capabilities, you can utilize the following cmdlet to print only name and values.
Output: