我在變數 $releaseDefinitions 中捕獲了 JSON 回應。有了這個,當我使用powershell在“環境”標簽下將“名稱”作為“STAGE1-PG-DB”傳遞時,我想將“ID”提取為“4598”。
非常感謝您對此的任何幫助。
{
"id": 516,
"environments": [
{
"id": 4598,
"releaseId": 516,
"name": "STAGE1-PG-DB",
"status": "notStarted",
},
{
"id": 4599,
"releaseId": 516,
"name": "STAGE2-PG-DB",
"status": "notStarted",
},
{
"id": 4600,
"releaseId": 516,
"name": "STAGE3-PG-DB",
"status": "notStarted",
}
]
}
uj5u.com熱心網友回復:
我相信您要求獲取名稱為“STAGE1-PG-DB”的 JSON 陣列物件。根據您提供的資訊,您會做這樣的事情(請參閱我的在線評論)
$releaseDefinitions = Get-Content -Path $inputFileName -Raw | ConvertFrom-Json
# use dot-notation to get the entire Environments array
# pipe the array through using the pipe character
# filter through the array where the key (Name) is equal to your value (STAGE1-PG-DB)
$releaseDefinitions.environments | Where-Object {$_.name -eq "STAGE1-PG-DB"}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/466228.html
