-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't use a variable on a filter for Get-MgDirectoryRole #2204
Comments
Thanks, but the actual issues is when using variables, for example: - DeletedDateTime Id Description
So using the literal works, but using a variable does not |
OK, so you've moved away from filtering on the Graph API, and instead filtering using PowerShell's Where-Object. These two things act quite differently. Filtering on PowerShell with Where-Object: You can use double quotes if you want to use a string, but you can omit these entirely if you're using a variable. e.g.
So far, I've been given a limited picture of what you're trying to acheive, otherwise I could offer up some more advice. In the first example, you've used the Get-MgDirectoryRole cmdlet and in the second one you've used Get-MgDirectoryRoleTemplate. Filtering via Graph API NOTE: You cannot filter Directory Role templates using the Graph API filter parameters, so you'd be better off filtering on the pipeline using Where-Object (See below): https://learn.microsoft.com/en-us/graph/api/directoryroletemplate-list?view=graph-rest-1.0&tabs=http#optional-query-parameters Filtering the same via Where-Object or Get-MgDirectoryRoleTemplate | Where-Object {$_.DisplayName -eq $role} |
Ok - Thanks my misunderstanding. Thanks for helping me out and the references. Very useful |
Thanks - all the best to you :) |
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
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
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
Screenshots
Additional context
The text was updated successfully, but these errors were encountered: