如何使用 Get-MgUserMemberOf cmdlet 获取 Microsoft Entra ID 用户的组成员身份

获取 Microsoft Entra ID 用户的组成员身份

了解用户所属的组对于访问控制、合规性和故障排除至关重要。虽然 Microsoft Graph PowerShell 的 Get-MgUserMemberOf cmdlet 可以帮助检索此信息,但它也存在脚本编写的常见挑战——复杂的语法、提升的权限以及有限的报告格式选项。

Microsoft Graph PowerShell 中的 Get-MgUserMemberOf cmdlet

前提条件

使用 Get-MgUserMemberOf cmdlet 之前:

  • Ensure Microsoft Graph PowerShell module is installed. If not, install it using this script:
    Install-Module Microsoft.Graph -Scope CurrentUser
  • Connect to Microsoft Graph PowerShell with the required permissions to view group memberships.
    Connect-MgGraph -Scopes "User.Read.All", "Group.Read.All"

使用 Get-MgUserMemberOf cmdlet

此 cmdlet 列出特定用户直接所属的组:

Get-MgUserMemberOf -UserId "john@zkyy.com"

示例用例和脚本

示例 1:列出单个用户的组成员身份

Get-MgUserMemberOf -UserId "jane@zkyy.com"

示例 2:按类型筛选组成员身份(例如,Security)

Get-MgUserMemberOf -UserId "Ash@zkyy.com" | Where-Object {$_.AdditionalProperties.'@odata.type' -eq "#microsoft.graph.group"}

示例 3:将组成员身份导出为 CSV

Get-MgUserMemberOf -UserId "Tessa@zkyy.com" | Select-Object Id, DisplayName | Export-Csv -Path "group-memberships.csv" -NoTypeInformation

支持的参数

参数 描述
-UserId 此参数用于指定要获取组成员身份的用户的唯一标识符。
-All 此参数检索所有结果。

使用 Graph PowerShell 脚本进行 Microsoft Entra ID 报告的限制

  • 需要理解嵌套对象属性和类型过滤器。
  • 没有内置的组类型过滤功能,如 Microsoft 365 和安全组,除非手动编写脚本。
  • 报告为纯文本,除非手动格式化和导出。
  • 无内置调度或电子邮件提醒功能。
  • 对于帮助台或非技术用户来说不够直观。

为什么 ADManager Plus 是 Microsoft Entra ID 报告的更佳选择

  • 只需几次点击即可生成关于 Microsoft Entra ID usersgroupslicenses 等的全面报告,无需复杂的 PowerShell 脚本。
  • 根据各种属性筛选报告,并以 CSV、PDF 和 HTML 等多种格式 导出数据,便于共享和文档管理。
  • 识别有风险的 Microsoft 365 对象,并主动减轻相关风险。
  • 安排报告自动运行,确保持续的可见性和合规性,无需人工干预。

使用 ADManager Plus 生成全面的 Microsoft Entra ID 报告

 
  • 获取 Microsoft Entra ID 用户的组成员身份
  • Microsoft Graph PowerShell 中的 Get-MgUserMemberOf cmdlet
  • 使用 Graph PowerShell 脚本进行 Entra ID 报告的限制
  • 为什么 ADManager Plus 是 Entra ID 报告的更佳选择
Active Directory管理与报告的一站式解决方案
电子邮件下载链接 Email the ADManager Plus download link