I have this response in json format:
{
"properties": {
"basic": {
"nodes_table": [
{
"node": "node1.prod.local:80",
"state": "active",
"weight": 1
},
{
"node": "node2.prod.local:80",
"state": "disabled",
"weight": 1
},
{
"node": "node3.prod.local:80",
"state": "disabled",
"weight": 1
},
{
"node": "node4.prod.local:80",
"state": "disabled",
"weight": 1
},
{
"node": "node5.prod.local:80",
"state": "active",
"weight": 1
}
]
}
}
}
What I am trying to do in my powershell script is to find out if given node(s) is available in the nodes_table and get their state. For example:
$nodes_table_hostnames = $GetNodesResponse.properties.basic.nodes_table.node
$nodes_table_status = $GetNodesResponse.properties.basic.nodes_table.state
if($nodes_table_hostnames -contains "node1.prod.local:80" -and $nodes_table_status -eq "active")
{
Write-Output "Node matches and is Active"
}
Problem: I am having an issue in getting the state of the "specific" node, so I want to check if "given" node is in the table and that node's state is active/disabled. How would I accomplish that in the script?