powershell - How do I retrieve the key value pairs from Get-AzureRmResourceGroup Tags -
i have resource group scheduled using tag has key value pair: "includeinschedule":"true"
when get-azurermresourcegroup -name myresourcegroup see:
resourcegroupname : myresourcegroup location : northcentralus provisioningstate : succeeded tags : name value ================= ====== includeinschedule true resourceid : /subscriptions/ea904806-082f-4ce5-9b66-288afd61f83e/resourcegroups/myresourcegroup when attempt read value in tag variable i'm coming unstuck. looks hashtable, get-azurermresourcegroup -name myresourcegroup | get-member tags suggests it's array of hashtable, reading right?
name membertype definition ---- ---------- ---------- tags property hashtable[] tags {get;set;} if pipe output get-azurermresourcegroup select-object , expand tags property get:
name value ===== ===== value true name includeinschedule this not expected see, expected see was:
includeinschedule true furthermore, when attempt assign tags variable can extract includeinschedule value, i'm not seeing values.
how extract value this?
yes, tags array of hashtables defined hashtable[] (notice square brackets).
each object in array hashtable like:
$t = @{ name = "includeinschedule"; value = "true" } $t name value ---- ----- value true name includeinschedule to access objects, use:
$includeinschedule = ((get-azurermresourcegroup -name myresourcegroup).tags | where-object { $_.name -eq 'includeinschedule'}).value #or $includeinschedule = (get-azurermresourcegroup -name myresourcegroup).tags | where-object { $_.name -eq 'includeinschedule'} | foreach-object { $_.value } output:
ps c:\users\frode> $includeinschedule true
Comments
Post a Comment