List policy assignments is throwing Invoke-WebRequest : The remote server returned an error: (400) Bad Request.

2022-10-27T12:02:01.46+00:00

List policy assignments is throwing (400) Bad Request error and the same API is working fine from graph exp.

$token = "xxx"  
    $Header = @{'Authorization' = "Bearer $token"; "Content-Type" = "application/json" }  
      
    $method = "GET"  
    $uri = "https://graph.microsoft.com/v1.0/policies/roleManagementPolicyAssignments?$filter=scopeId eq '/' and scopeType eq 'Directory'"  
      
    $response = Invoke-WebRequest -Headers $Header -Uri $uri -Method $method -UseBasicParsing  

I could see that it has all the required permissions.
254669-image.png
Can anyone check and let us know the issue??

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,549 questions
Microsoft Entra
0 comments No comments
{count} votes

Accepted answer
  1. Shivam Dhiman 5,946 Reputation points
    2022-10-27T13:01:54.287+00:00

    Hi @Krupa Gundraju (Larsen & Toubro Infotech Limit)

    When you are using $filter in PowerShell it will take it as Variable, so you need to use it like `$filter in above API.

    Please refer to this similar case for more details.

    Hope this helps.
    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.

    0 comments No comments

0 additional answers

Sort by: Most helpful