Using Get-MgGroupOwnerCount in Graph PowerShell

The Get-MgGroupOwnerCount cmdlet is a powerful tool in the Microsoft Graph PowerShell module that allows administrators to retrieve the total number of owners for a Microsoft 365 group. Managing group ownership is crucial in organizations where multiple individuals oversee resources like Teams, SharePoint sites, and security groups. This cmdlet simplifies the process by returning the owner count without needing to iterate through each group owner manually.

Cmdlet Syntax

Get-MgGroupOwnerCount -GroupId <String> [-Filter <String>] [-ConsistencyLevel <String>] 

Parameters:

  • -GroupId: (required) Specifies the unique identifier of the group for which you want to retrieve the owner count.
  • -Filter: Allows filtering results based on a string query.
  • -ConsistencyLevel: When used with the value eventual, this ensures that the results are accurate, especially when working with large datasets.

Usage Examples

Example: Retrieve the Owner Count for a Specific Group

$groupId = "4d77f8d7-e99a-4e45-84e4-6f8b58b983bc"
Get-MgGroupOwnerCount -GroupId $groupId

Cmdlet Tips

  • Use the Right Filters: The -Filter parameter allows powerful filtering options, which help you narrow down results based on group properties. Ensure you’re familiar with available query options to optimize the cmdlet.
  • Leverage the -ConsistencyLevel Parameter: When retrieving data from large directories, using the eventual consistency level ensures that the returned results are more precise and up-to-date.
  • Check Permissions: Ensure you have appropriate permissions to access group ownership details. Administrative roles such as Global Admin or Group Admin are typically required.

Common Errors & Solutions

Error Cause Solution
Group Not Found When you attempt to query a group that doesn’t exist or the GroupId is incorrect, you might encounter an error similar to: Resource '4d77f8d7-e99a-4e45-84e4-6f8b58b983bc' not found. Verify the group exists by using the Get-MgGroup cmdlet and ensure that the GroupId you are using is accurate.
Invalid Filter Clause If the -Filter parameter contains an unsupported or incorrect syntax, the cmdlet may fail with an error like: Invalid filter clause: 'ownerCount gt 1'. Ensure that the filter syntax is valid and that you’re filtering based on properties supported by the Microsoft Graph API. Always refer to the OData filter documentation for guidance.

Use Cases

  • Auditing Group Ownership: Organizations often need to audit the ownership structure of M365 groups to ensure proper delegation. The Get-MgGroupOwnerCount cmdlet simplifies this by providing an accurate count of group owners without listing all owners. This is especially useful for auditing large numbers of groups.
  • Automating Group Management: In large environments where automation is key, administrators may need to regularly check groups with low or high ownership counts to ensure compliance with organizational policies. For instance, groups with too few or too many owners may require action. Using this cmdlet in scripts can alert administrators to groups requiring attention.
  • Monitoring Groups for Security Compliance: Some organizations have policies requiring at least two owners for important groups, such as security groups or project-based Teams. With the -Filter parameter, you can identify groups that don’t meet this requirement and take corrective action.

Conclusion

The Get-MgGroupOwnerCount cmdlet is a versatile and valuable tool for administrators managing Microsoft 365 groups. It simplifies the process of tracking group ownership, ensuring that your organization stays compliant with group management policies. Whether you’re auditing ownership or automating group administration tasks, this cmdlet will help you streamline operations and maintain control over your environment.

Make sure to explore the full capabilities of this cmdlet by using filters and checking for potential errors that may arise. With proper usage, Get-MgGroupOwnerCount can become an integral part of your administrative toolkit.

© m365corner.com. All Rights Reserved. Design by HTML Codex