The Get-MgGroup cmdlet allows Microsoft 365 administrators to retrieve directory groups including Microsoft 365 groups, security groups, and distribution lists. When you want to quickly locate groups based on partial matches in their name or description, the -Search parameter comes in handy.
This article explains how to correctly use -Search with Get-MgGroup, including working examples, syntax rules, and key considerations to avoid common errors.
Get-MgGroup -Search '"property:value"' -ConsistencyLevel eventual -All
The -Search parameter must follow the property:value format and requires -ConsistencyLevel eventual.
Get-MgGroup -Search '"displayName:Marketing"' -ConsistencyLevel eventual -All
Returns all groups with "Marketing" in their display name, such as Marketing Team, Global Marketing, etc.
Get-MgGroup -Search '"displayName:Hello Team"' -ConsistencyLevel eventual -All
Finds groups named Hello Team or containing those words in the display name.
Get-MgGroup -Search '"description:Internal Project"' -ConsistencyLevel eventual -All
Returns all groups whose description includes the phrase Internal Project.
Get-MgGroup -Search '"displayName:HR"' -ConsistencyLevel eventual -All -Property displayName, mail, id
Fetches only HR-related groups and limits the returned fields to Display Name, Mail, and ID.
Get-MgGroup -Search '"displayName:Project"' -ConsistencyLevel eventual -All |
Select-Object DisplayName, Description, Mail |
Export-Csv "ProjectGroups.csv" -NoTypeInformation
Searches for all project-related groups and exports them to a CSV file for reporting.
Get-MgGroup -Search '"mail:allcompany@7xh7fj.onmicrosoft.com"' -ConsistencyLevel eventual -All
Searches for the group with mail address allcompany@7xh7fj.onmicrosoft.com and outputs the group details
You must search using a supported property like displayName or description:
-Search '"displayName:Finance"' # β Valid
-Search '"Finance"' # β Invalid
The entire property:value pair should be inside double quotes to be parsed correctly.
This is required for -Search to work with Graph API:
Get-MgGroup -Search '"displayName:Admin"' -ConsistencyLevel eventual -All
Currently, only displayName and description are searchable. Other fields like mail, mailNickname, or groupTypes do not work with -Search.
Thereβs no need to match casing, and partial values like "displayName:Sales" will match Sales Team, Sales India, etc.
Error Message | Cause | Solution |
Clause 'Team Alpha' in $search is not of right format 'property:value' | Missing property: prefix | Use -Search '"displayName:Team Alpha"' |
Request_UnsupportedQuery | Used unsupported field like mail or id | Only use displayName or description |
-Search used without -ConsistencyLevel | Required parameter omitted | Always include -ConsistencyLevel eventual |
-Search
Works Only on Select Properties-Search
parameter supports only specific fields like displayName
and description
.-Search
vs -Filter
β Know the Difference-Search
for broad keyword-based discovery, and -Filter
when querying specific attributes like groupTypes
or mailEnabled
.-Filter
is the more appropriate choice.
The -Search parameter in Get-MgGroup is ideal for quick lookups based on group names or descriptions. Whether you're searching for Teams groups, project groups, or admin lists, using -Search with the right syntax and flags gives fast and relevant results.
Just remember:
© m365corner.com. All Rights Reserved. Design by HTML Codex