gpt4 book ai didi

powershell - 如何从Powershell脚本中的列表中查询

转载 作者:行者123 更新时间:2023-12-03 00:34:03 27 4
gpt4 key购买 nike

我有json格式的响应:

{
"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
}
]
}
}
}

我要在Powershell脚本中尝试执行的操作是找出是否可以在node_table中使用给定的节点并获取其状态。例如:
$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"
}

问题:
我在获取“特定”节点的状态时遇到问题,因此我想检查表中是否存在“给定”节点,并且该节点的状态为 Activity /禁用。我将如何在脚本中完成此任务?

最佳答案

$Active = $GetNodesResponse.properties.basic.nodes_table |
Where {$_.Node -eq "node1.prod.local:80" -and $_.state -eq "active"}
If ($Active) {Write-Output "Node matches and is Active"}

关于powershell - 如何从Powershell脚本中的列表中查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50104540/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com