Search Group Members in M365 Using Get-MgGroupMember Cmdlet

The -Search parameter in the Get-MgGroupMember cmdlet allows you to search for group members based on specific attributes. This parameter accepts a search string formatted as "<PropertyName>:<SearchValue>", enabling you to filter members whose specified property matches the search value. Commonly searched properties include displayName, mail, and userPrincipalName.​

Usage Examples:

  1. Search by Display Name: To find members with a display name containing "John":
  2. Get-MgGroupMember -GroupId "<GroupId>" -Search "displayName:John" -ConsistencyLevel eventual

    This command retrieves members whose display name includes "John".

  3. Search by Email Address: To locate members with an email address containing "example.com":
  4. Get-MgGroupMember -GroupId "<GroupId>" -Search "mail:example.com" -ConsistencyLevel eventual

    This command fetches members whose email address includes "example.com".

  5. Search by User Principal Name (UPN): To find members with a UPN containing "user":
  6. Get-MgGroupMember -GroupId "<GroupId>" -Search "userPrincipalName:user" -ConsistencyLevel eventual

    This command retrieves members whose UPN includes "user".

Important Considerations:

  • Consistency Level: When using the -Search parameter, it's essential to set the -ConsistencyLevel parameter to eventual. This setting ensures that the search operation works correctly.
  • Search Behavior: The -Search parameter performs a case-insensitive search and matches substrings within the specified property. For example, searching for "John" in the display name will return members with display names like "John Doe", "Johnny", or "Alice Johnson".​
  • Performance Considerations: Using the -Search parameter can be resource-intensive, especially in large directories. To optimize performance, ensure that your search queries are as specific as possible.​

By utilizing the -Search parameter effectively, administrators can efficiently locate and manage group members based on specific attributes, streamlining group management tasks within Microsoft 365 environments

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