Skip to content

Can't use a variable on a filter for Get-MgDirectoryRole #2204

Closed
@webstean

Description

@webstean

Thanks for reporting the bug. Please ensure you've gone through the following checklist before opening an issue:

Describe the bug
Can't use a variable on a filter for Get-MgDirectoryRole

To Reproduce
Steps to reproduce the behavior:
PS C:\Users\andreww> $role = "Global Administrator"
PS C:\Users\andreww> Get-MgDirectoryRole -Filter "DisplayName eq $role"
Get-MgDirectoryRole_List: Invalid filter clause: Syntax error at position 35 in 'DisplayName eq Global Administrator'.

Status: 400 (BadRequest)
ErrorCode: BadRequest
Date: 2023-07-31T10:29:37

Headers:
Transfer-Encoding : chunked
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : 1d8c6e96-bfc8-4bf4-8324-e00b9245a4de
client-request-id : 48247b71-88c4-4b45-ac5f-4a388c7fa5fb
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"Australia Southeast","Slice":"E","Ring":"4","ScaleUnit":"001","RoleInstance":"ML1PEPF00004AF4"}}
Date : Mon, 31 Jul 2023 10:29:36 GMT

Expected behavior
Returns details of role

Debug Output

Run the problematic command with -Debug and paste the resulting debug stream below.
⚠ ATTENTION: Be sure to remove any sensitive information that may be in the logs.
PS C:\Users\andreww> Get-MgDirectoryRole -Filter "DisplayName eq $role" -debug
DEBUG: [CmdletBeginProcessing]: - Get-MgDirectoryRole begin processing with parameterSet 'List'.
DEBUG: [Authentication]: - AuthType: 'Delegated', TokenCredentialType: 'InteractiveBrowser', ContextScope: 'CurrentUser', AppName: 'Microsoft Graph Command Line Tools'.
DEBUG: [Authentication]: - Scopes: [AccessReview.Read.All, AdministrativeUnit.Read.All, Analytics.Read, AppCatalog.Read.All, Application.Read.All, Application.ReadWrite.All, AuditLog.Read.All, Directory.Read.All, Group.Read.All, openid, People.Read.All, profile, Sites.Read.All, User.Read, User.Read.All, User.ReadWrite.All, email, SecurityEvents.Read.All].
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://graph.microsoft.com/v1.0/directoryRoles?$filter=DisplayName eq Global Administrator

Headers:
FeatureFlag : 00000043
Cache-Control : no-store, no-cache
User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.25915; en-AU),PowerShell/7.3.6
Accept-Encoding : gzip
SdkVersion : graph-powershell/2.1.0
client-request-id : 2fa7a2e3-19b8-4fb2-88c6-feab3bc7e966

Body:

Module Version

Please run Get-Module Microsoft.Graph* after cmdlet execution and paste the output below.
If a module cannot be installed or imported, please run Get-Module -ListAvailable and paste the output.
PS C:\Users\andreww> Get-Module Microsoft.Graph*

ModuleType Version PreRelease Name ExportedCommands


Script 2.1.0 Microsoft.Graph.Applications {Add-MgApplicationKey, Add-MgApplicationPassword,…
Script 2.1.0 Microsoft.Graph.Authentication {Add-MgEnvironment, Connect-MgGraph, Disconnect-M…
Script 2.1.0 Microsoft.Graph.Identity.Directory… {Confirm-MgContactMemberGroup, Confirm-MgContactM…
Script 2.1.0 Microsoft.Graph.Security {Add-MgSecurityCaseEdiscoveryCaseCustodianHold, A…

Environment Data

Please run $PSVersionTable and paste the output below. If running the Docker container image, indicate the tag of the image used and the version of Docker engine.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions