Skip to content
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

Invoke-MGGraphrequest not escaping/encoding URI correctly in PowerShell V5 #2942

Closed
kayasax opened this issue Sep 5, 2024 · 3 comments
Closed
Assignees
Labels

Comments

@kayasax
Copy link

kayasax commented Sep 5, 2024

Describe the bug

Depending on the parameters order of my query the command will succeed or failed:

Non-working URI: $uri="https://graph.microsoft.com/v1.0/policies/roleManagementPolicyAssignments?`$filter=scopeId eq '/' and scopeType eq 'DirectoryRole' and roleDefinitionId eq 'c2314e04-b23a-4dd5-915f-b0ab7487c9d9'"

Working URI: $uri="https://graph.microsoft.com/v1.0/policies/roleManagementPolicyAssignments?`$filter=scopeType eq 'DirectoryRole' and roleDefinitionId eq 'c2314e04-b23a-4dd5-915f-b0ab7487c9d9' and scopeId eq '/'"

command: Invoke-MgGraphRequest $uri -Method get -Verbose

2024-09-04_11h36_47

URI is half encoded in V5 but OK in V7:

2024-09-04_10h58_50

Microsoft.Graph.Authentication version 2.23.0

this is working fine with PowerShell V7

Expected behavior

the result should be the same whatever the parameters order

How to reproduce

Invoke-MgGraphRequest $uri -Method get -Verbose
with above URIs

SDK Version

2.23.0

Latest version known to work for scenario above?

No response

Known Workarounds

change parameters order

Debug output

Click to expand log ```

DÉBOGUER : GET
https://graph.microsoft.com/v1.0/policies/roleManagementPolicyAssignments?$filter=scopeId%20eq%20'/'%2520%2520and%2520scopeType%2520eq%2520'DirectoryRo
le'%2520and%2520roleDefinitionId%2520eq%2520'c2314e04-b23a-4dd5-915f-b0ab7487c9d9'
HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Vary: Accept-Encoding
Strict-Transport-Security: max-age=31536000
request-id: e5794459-7150-4d4a-80dd-cb155fde8657
client-request-id: c9f4ef07-3e2a-4df4-9737-8de15ff536f2
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"France Central","Slice":"E","Ring":"5","ScaleUnit":"001","RoleInstance":"PA2PEPF00012B8E"}}
Date: Thu, 05 Sep 2024 17:31:38 GMT
Content-Encoding: gzip
Content-Type: application/json

{"error":{"code":"BadRequest","message":"Invalid filter clause: Syntax error: character '%' is not valid at position 14 in 'scopeId eq
'/'%20%20and%20scopeType%20eq%20'DirectoryRole'%20and%20roleDefinitionId%20eq%20'c2314e04-b23a-4dd5-915f-b0ab7487c9d9''.","innerError":{"date":"2024-09
-05T17:31:39","request-id":"e5794459-7150-4d4a-80dd-cb155fde8657","client-request-id":"c9f4ef07-3e2a-4df4-9737-8de15ff536f2"}}}

</details>


### Configuration

Win11 64b

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.22621.4155
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.4155
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

### Other information

_No response_
@kayasax kayasax added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Sep 5, 2024
@timayabi2020 timayabi2020 self-assigned this Sep 23, 2024
@timayabi2020
Copy link
Contributor

@kayasax is the order change scenario in PowerShell 5 or 7? Do you mean that this experience is only in PowerShell 5? Is the experience the same when using the alternative cmdlet Get-MgPolicyRoleManagementPolicyAssignment -Filter "scopeId eq '/' and scopeType eq 'DirectoryRole' and roleDefinitionId eq 'c2314e04-b23a-4dd5-915f-b0ab7487c9d9'" -Debug ?

@timayabi2020 timayabi2020 added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Sep 24, 2024
@kayasax
Copy link
Author

kayasax commented Sep 24, 2024

Hi @timayabi2020 , yes the error is surfacing only in PowerShell 5.
Both URIs working fine in PS7.
I just tried the alternative cmdlet and its working fine from V 5 and 7.
But my goal was to rely on invoke-mggraphrequest only to avoid the need to install other modules.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Sep 24, 2024
@kayasax
Copy link
Author

kayasax commented Sep 24, 2024

don't know why but now it s working from V5! You can close the issue thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants