【发布时间】:2019-10-30 17:13:00
【问题描述】:
我想使用 azure 函数的 powershell 脚本读取和列出特定 AD 组的成员。要连接 AD,我使用的是服务主体。连接到 AzureAD 是成功的,但是尝试访问 AD 组给我一个错误(在这个阶段我只想得到一个特定的组并回显它):
System.Management.Automation.RemoteException: Error occurred while executing GetGroups
Code: Authorization_RequestDenied
Message: Insufficient privileges to complete the operation.
RequestId: <requestID>
DateTimeStamp: Mon, 14 Oct 2019 20:40:26 GMT
HttpStatusCode: Forbidden
HttpStatusDescription: Forbidden
HttpResponseStatus: Completed
为什么会这样?有人在 azure 函数中使用 azuread 模块命令吗?我已为此应用授予 ms 图表权限:
$Script={
param ()
##Save AzureAD module to the modules folder before publishing
Import-Module .\modules\AzureAD
$appId = "<AppId>"
$thumb = "<CertThumb>"
$tenantId = "TenantID"
Connect-AzureAD -TenantId $tenantId -ApplicationId $appId -CertificateThumbprint $thumb
$groupName = "<Name of the group>"
$group = Get-AzureADGroup -SearchString $groupName
#or
#$group = Get-AzureADGroup -ObjectId "<object id>"
echo $group
}
&$env:64bitPowerShellPath -WindowStyle Hidden -NonInteractive -Command $Script
请注意,我的代码被包装到 $Script 变量中,并添加了最后一行以使代码作为临时解决方法工作,直到将 AD 模块添加到 PS Core: https://github.com/Azure/azure-functions-powershell-worker/issues/232
【问题讨论】:
-
您可以尝试在 AAD Graph API 上授予它类似的权限吗? (Windows Azure Active Directory)只是一种预感,但我记得一些 PowerShell cmdlet 使用了这个旧 API。
标签: azure powershell azure-active-directory azure-functions azure-ad-graph-api