【发布时间】:2021-09-06 15:01:55
【问题描述】:
我正在尝试通过一个小的 Powershell 脚本使用 MS 图形 API,如此处所述 https://docs.microsoft.com/en-us/graph/api/riskyusers-list?view=graph-rest-beta&tabs=http 这个过滤器没有给出任何结果,如果我删除它它可以工作,但没有给出完整的列表(只有几个结果)
$ApplicationID = "45xxxxxxxx"
$TenatDomainName = "2a3xxxxx"
$AccessSecret = Read-Host "Enter Secret"
$Body = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
client_Id = $ApplicationID
Client_Secret = $AccessSecret
}
$ConnectGraph = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenatDomainName/oauth2/v2.0/token" -Method POST -Body $Body
$token = $ConnectGraph.access_token
#$GrapRisk = "https://graph.microsoft.com/v1.0/identityProtection/riskyUsers"
$GrapRisk = "https://graph.microsoft.com/beta/identityProtection/riskyUsers?$filter=riskLevel eq microsoft.graph.riskLevel'medium'"
$riskyList= (Invoke-RestMethod -Headers @{Authorization = "Bearer $($token)"} -Uri $GrapRisk -Method Get).value |select userPrincipalName, riskState, riskLastUpdatedDateTime, riskLevel
$riskyList
我通过 Powershell ISE 执行此脚本,但即使使用 curl 和终端,我也无法使用 filter 参数。 谢谢
【问题讨论】:
-
将 url 中的
?$filter更改为?`$filter$ 将阻止 PowerShell 尝试将其解析为插值变量
标签: azure powershell graph