我试图通过使用OData $filter查询从Microsoft获得一个子集的机器,它遵循微软的指令(https://learn.microsoft.com/en-us/windows/security/threat-protection/microsoft-defender-atp/exposed-apis-odata-samples),但不管我做什么,我都会得到相同的机器集,限制在10,000台。
所以,我下面的代码不能正常工作的原因。我做错了什么?另外,我如何获得超过1万台机器?
我从下面的代码中删除了tenantId、appId和appSecret变量。
更新:--我注意到在运行脚本后在PowerShell ISE中检查$machinesUrl2变量的值时,它会显示URI中缺少"$filter“。以下是变量$machinesUrl2的输出:
https://api.securitycenter.windows.com/api/machines?=healthStatus+eq+'Inactive'是什么导致了"$filter“的下降?这是正常行为吗?
谢谢,
$resourceAppIdUri = 'https://securitycenter.onmicrosoft.com/windowsatpservice'
$oAuthUri = "https://login.windows.net/$TenantId/oauth2/token"
$authBody = [Ordered] @{
resource = "$resourceAppIdUri"
client_id = "$appId"
client_secret = "$appSecret"
grant_type = 'client_credentials'
}
$authResponse = Invoke-RestMethod -Method Post -Uri $oAuthUri -Body $authBody -ErrorAction Stop
$aadToken = $authResponse.access_token
$machinesUrl2 = "https://api.securitycenter.windows.com/api/machines?$filter=healthStatus+eq+'Inactive'"
$headers = @{
'Content-Type' = 'application/json'
Accept = 'application/json'
Authorization = "Bearer $aadToken"
}
$machinesResponse = Invoke-WebRequest -Method Get -Uri $machinesUrl2 -Headers $headers -ErrorAction Stop
$machines = ($machinesResponse | ConvertFrom-Json).value发布于 2020-09-24 22:11:05
当我试图弄清楚为什么$filter会从查询字符串中删除时,我找到了答案。
它需要在“$filter”前面添加一个反勾字符(‘)。
https://api.securitycenter.windows.com/api/machines?`$filter=healthStatus+eq+'Inactive'将此字符添加到查询字符串后,此Microsoft文档上的代码开始工作。
https://stackoverflow.com/questions/63937238
复制相似问题