Get-MgGroup/Get-MgBetaGroup: -Filter with 'displayName eq' fails to match names with trailing whitespace/newlines #3316
Labels
status:waiting-for-triage
An issue that is yet to be reviewed or assigned
type:bug
A broken experience
Describe the bug
Issue Summary
The
-Filter
parameter withdisplayName eq
fails to match group names that contain trailing whitespace or newline characters (\r\n
), while the same names are successfully matched usingstartswith()
filter. This creates inconsistent behavior and breaks automation scripts that rely on exact name matching.Root Cause Identified
Groups with names containing invisible trailing whitespace or newline characters cannot be found using the exact match syntax (
displayName eq 'Name'
), despite being shown in the results when using startswith(displayName,'Name'). This is confirmed by examining the response JSON, which shows
\r\n` at the end of the displayName value.Expected behavior
The filter
displayName eq 'Name'
should properly match group names regardless of trailing whitespace or newline characters, especially since these characters are often invisible in the admin interfaces and can be difficult to detect.Alternatively, if exact matching is required including whitespace, then the documentation should clearly state this behavior and provide guidance on handling invisible characters in filter conditions.
How to reproduce
Get-MgBetaGroup -Filter "displayName eq 'AppDevice-Adobe Creative Cloud SDL'"
Get-MgBetaGroup -Filter "startswith(displayName,'AppDevice-Adobe Creative Cloud SDL')" -ConsistencyLevel eventual
\r\n
in the displayNameConfirmed in Graph Explorer: Direct API calls to
/beta/groups?$filter=displayName eq 'AppDevice-Adobe Creative Cloud SDL'
return no results, while/beta/groups?$filter=startswith(displayName,'AppDevice-Adobe Creative Cloud SDL')
returns the group with trailing whitespace.SDK Version
2.27.0
Latest version known to work for scenario above?
No response
Known Workarounds
Use startswith() as a workaround and handle any additional filtering in PowerShell:
Get-MgBetaGroup -Filter "startswith(displayName,'exact-name')" -ConsistencyLevel eventual
Edit the group name in the admin portal to remove trailing whitespace (requires careful editing as the whitespace is invisible).
For programmatic access, trim the input string and the strings from the results:
$name = "AppDevice-Adobe Creative Cloud SDL".Trim()
Get-MgBetaGroup -Filter "startswith(displayName,'$name')" | Where-Object { $_.DisplayName.Trim() -eq $name }
Debug output
Click to expand log
```Debug Output
When trying to filter with an exact match:
Configuration
Name Value
PSVersion 5.1.20348.2849
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.20348.2849
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Other information
This appears to be an issue with how the Graph API handles whitespace in filter conditions. The trailing whitespace characters are not visible in the admin portal, making this issue particularly difficult to diagnose.
The fact that modifying the group name by removing and re-adding the last character (thereby removing the invisible whitespace) resolves the issue confirms that this is a whitespace handling problem in the filter mechanism, not a general failure of the
eq
operator.This issue has significant implications for automation scripts that rely on exact group name matching, as they must now implement additional logic to handle invisible whitespace characters.
The text was updated successfully, but these errors were encountered: