試圖查找這個,但不太明白如何完成這個。我需要做的是過濾掉以下內容:
$response = Invoke-RestMethod 'cannot share of course' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
回應(出于某種原因,此處剪切并掩蓋了某些部分):
{
"url": "***",
"id": ***,
"guid": "***",
"name": "***",
"check_type": "***",
"check_type_name": "Real Browser, Chrome",
"check_type_api": "browser",
"enabled": true,
"location": "***",
},
"tags": {
"Country": "***",
"ITSystemCode": "***"
}
}
我能夠獲取內容,我希望能夠提取“id”和“name”,以及它是否“啟用”真或假。嘗試使用 Where-Object 但似乎是錯誤的做法?
非常感謝提前!
uj5u.com熱心網友回復:
感謝您的提示。我會回答這個問題,因為這確實幫助我完成了我的任務。
我所做的是在第二行之后添加“$response | Select id,name”,它從請求的內容/JSON 中選擇Id和Name并僅顯示Id和Name值,以及我將串列匯出到的額外內容在第 3 行使用Out-File "C:\Code\checks.csv"的 .csv 檔案。
$response = Invoke-RestMethod '***' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
$response | Select id,name | Out-File "C:\Code\checks.csv"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/407471.html
標籤:
上一篇:使用Powershell撰寫腳本的服務器功能/角色服務設定
下一篇:將變數內容匯出到檔案
