有什么方法可以查看用户被分配到哪些 Azure 目录角色(内置角色)?
我需要找到用户并转到“分配的角色”时获得的信息。 我尝试在 Azure 文档中找到一些命令,但没有成功。
提前致谢
最简单的方法是使用 PowerShell 和 Microsoft Graph PowerShell SDK。请参阅下面的示例。
$tenant = "yourtenant.onmicrosoft.com";
$disconnectGraphAfterExecution = $true;
Connect-MgGraph -Scopes User.Read.All,RoleManagement.Read.All -TenantId $tenant -NoWelcome;
$portalUsers = Get-MgBetaUser -all -filter "creationType eq 'Invitation'";
foreach ($portalUser in $portalUsers) {
$directoryRolesForUser = "";
Get-MgBetaUserMemberOfAsDirectoryRole -UserId $user.Id | ForEach-Object { $directoryRolesForUser += $_.DisplayName + ", "; };
$directoryRolesForUser = $string.TrimEnd(', ');
$portalUsers | Add-Member "DirectoryRoles" $directoryRolesForUser -Force;
}
$portalUsers | Select-Object Id, DisplayName, mail, CreationType, ExternalUserState, DirectoryRoles | fl;
if ($disconnectGraphAfterExecution) { Disconnect-MgGraph; };
首先,我们有 graph API 来列出所有内置角色。这样我们就知道它也是一个目录对象。
因此我们可以在用户方法中搜索,发现我们有 relationship
MemberOf
来为我们提供用户所属的目录对象。
使用如下 API 可以为我们提供属性。
获取 https://graph.microsoft.com/v1.0/users/user_id?$expand=memberOf($select=displayName,id)
证明memberof就是我们需要获取的,我们只需要添加一个过滤器就可以获取所有的目录角色。这是我找到的 API。
https://graph.microsoft.com/v1.0/Users/user_id/memberOf/$/microsoft.graph.directoryRole