Skip to content

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

@kayasax

Description

@kayasax

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_

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions