Share via

Powershell to selecting the value

Kalaimani Thirupathi 411 Reputation points
2021-07-20T14:11:46.067+00:00

Dear All,

I have keys and values but am not able to select one particular value.

Basically, trying to check one of the values of the key.

Example: I need to get the only Key for ghs-managedbackup is Value status true or false

PS C:\> $SubsTags.Tags

Key Value


ghs-compliance soc2
ghs-managedossupport true
ghs-managedrbac true
ghs-managedmonitoring true
ghs-managednetworking true
ghs-subscriptiontype fully managed
ghs-managedbackup true
ghs-managedconfigmanagement true
ghs-managedpatching true

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author

Rich Matheisen 48,116 Reputation points
2021-07-20T14:41:43.567+00:00

Is this what you're trying to do? I'm assuming that $SubsTags.Tags holds a hash table. I'm not sure if "true" (in your situation) is a string value or a boolean value (i.e. $true or $false).

$hash = @{
    "ghs-compliance"="soc2"
    "ghs-managedossupport"="true"
    "ghs-managedrbac"=" true"
    "ghs-managedmonitoring"="true"
    "ghs-managednetworking"="true"
    "ghs-subscriptiontype"="fully managed"
    "ghs-managedbackup"="true"
    "ghs-managedconfigmanagement"="true"
    "ghs-managedpatching"=" true"
}

if ($hash["ghs-managedbackup"] -eq "true"){
    Write-Host "It's true!"
}
else{
    Write-Host "It's NOT true."
}

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.