The Get-MgUserMemberOfCount cmdlet is part of the Microsoft Graph PowerShell module, enabling administrators to count the number of directory objects (such as groups) a user is a member of in Microsoft 365. This cmdlet is particularly useful for managing and auditing user memberships within an organization.
Get-MgUserMemberOfCount [-UserId <String>] [-Filter <String>] -ConsistencyLevel eventual
Parameters
Example 1: Directly Executing Get-MgUserMemberOfCount
Get-MgUserMemberOfCount -ConsistencyLevel Eventual
This command retrieves the count of directory objects the current user is a member of, using eventual consistency for the query.
Example 2: Passing -UserId Parameter
Get-MgUserMemberOfCount -UserId "samadmin@7xh7fj.onmicrosoft.com" -ConsistencyLevel Eventual
This command retrieves the count of directory objects that the user with the UPN samadmin@7xh7fj.onmicrosoft.com is a member of, using eventual consistency.
Example 3: Using -Filter With Get-MgUserMemberOfCount
Get-MgUserMemberOfCount -UserId "samadmin@7xh7fj.onmicrosoft.com" -Filter "groupTypes/any(c:c eq 'Unified')" -ConsistencyLevel Eventual
This command retrieves the count of unified groups that the user samadmin@7xh7fj.onmicrosoft.com is a member of, using a filter to specify unified groups and eventual consistency.
The Get-MgUserMemberOfCount cmdlet is a powerful tool for administrators to efficiently count the memberships of users within an organization. By leveraging parameters like -Filter and -ConsistencyLevel, you can tailor your queries to meet specific requirements. Always ensure that parameter values are accurate and that the executing account has appropriate permissions to avoid common errors.
© m365corner.com. All Rights Reserved.