我一直在寻找一种使用 MS Graph PowerShell module 从 Azure 中删除目录角色成员的方法。但是,我似乎找不到任何 cmdlet 来执行此操作。
我目前正在使用 New-MgDirectoryRoleMemberByRef cmdlet 以便将用户添加到我们所照顾的租户的目录角色(例如全局管理员)中,但是我似乎找不到随后删除它们的方法。
我可以从this article here看到MS Graph API 公开了删除功能,但没有详细说明能够执行此操作的 PowerShell cmdlet。
任何人都可以为我指明如何使用 MS Graph PowerShell SDK 从角色中删除用户的正确方向吗?
最佳答案
目前似乎没有适用于此目的的 PowerShell cmdlet。 migration documentation列出与 Remove-AzureADDirectoryRoleMember
等效的内容是 Remove-MgDirectoryRoleScopedMember
,但这似乎不正确,因为此 cmdlet 适用于作用域为管理单位的角色。
与此同时,您仍然可以使用 Azure AD PowerShell cmdlet 或 Graph API。
通过 PowerShell 使用 Graph API
您需要一个访问 token ,该 token 通常是使用客户端应用程序(应用程序注册)获取的。请求 header 中需要此访问 token 。
可用于测试目的的更手动方法是打开 Graph Explorer ,登录,然后单击访问 token 按钮。
客户端应用程序(或 Graph Explorer 用户)还需要权限 RoleManagement.ReadWrite.Directory
(如 documentation 中所述)
# Example request
$roleId = ""
$roleTemplateId = ""
$userId = ""
$accessToken = ""
# Use this endpoint when using the role Id
$uri = "https://graph.microsoft.com/v1.0/directoryRoles/$roleId/members/$userId/`$ref"
# Use this endpoint when using the role template ID
# $uri = "https://graph.microsoft.com/v1.0/directoryRoles/roleTemplateId=$roleTemplateId/members/$userId/`$ref"
# Splatted parameters for the HTTP request
$params = @{
Headers = @{ Authorization = "Bearer $accessToken" }
Method = "Delete"
Uri = $uri
}
Invoke-RestMethod @params
使用图形浏览器
使用 DELETE
方法向任意端点发出请求
DELETE /directoryRoles/{role-id}/members/{id}/$ref
DELETE /directoryRoles/roleTemplateId={roleTemplateId}/members/{id}/$ref
关于azure - 如何删除 MS Graph PowerShell 模块中的目录角色成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72637942/