我正在尝试获取resourceProvisioningOptions = Team的所有组的列表,这是通过API调用获取所有数据的网址:
$clientID = xxxx
$tenantName = xxxx
$ClientSecret = xxxx
$resource = "https://graph.microsoft.com/"
$ReqTokenBody = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
client_Id = $clientID
Client_Secret = $clientSecret
}
$authheader = @{
'Authorization' = "Bearer $($Tokenresponse.access_token)"
'Content-Type'='application\json'
}
$TokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantName/oauth2/v2.0/token" -Method POST -Body $ReqTokenBody
$test = "'Team'"
$apiUrl = 'https://graph.microsoft.com/beta/groups?$filter=resourceProvisioningOptions/Any(x:x eq {0})' -f $test
$Data = Invoke-RestMethod -Uri $apiUrl -Headers $authheader -Body $ReqTokenBody -Method Get
$Groups = ($Data | select-object Value).Value | Select-Object displayName, id, description, mail | Out-File .\texxtfile.txt
但是,尽管我拥有进行API调用所需的所有权限,但在尝试运行脚本时却遇到401错误。
答案 0 :(得分:0)
您可能已在AAD应用程序中选择了应用程序权限。有一个附加步骤。您需要在应用程序注册门户网站上获得管理员的同意,才能使用Group.Read.All来运行此程序。如果您尚未在用户界面中完成此操作,则会失败。