Trying to use powershell to get a list of planner plans associated with groups

Kathy Blasco 101 Reputation points
2021-02-04T20:30:04.087+00:00

I am trying to use graph to get a list of planner plans assocaited with each Office 365 group.

I have configured my AzureAD app with the correct permissions per documentation. Specifically Groups.ReadWrite.All.

I used '$AccessToken = (Get-PnPGraphAccessToken)' to get and store my AccessToken.

I can issue statements to return group information except for when it comes to plans.

$headers = @{ Authorization=("Bearer " + $AccessToken) }
$uri = "https://graph.microsoft.com/beta/groups/{groupid}/planner/plans"
$webRequest = Invoke-RestMethod –Uri $uri –Method Get -Headers @{Authorization = "Bearer $AccessToken"} -ContentType "application/json"

I am getting the following error:

Invoke-RestMethod : {
"error": {
"code": "UnknownError",
"message": "\r\n\r\n\r\n\r\n401 - Unauthorized: Access is denied due to invalid credentials.\r\n\r\n\r\n\r\n\r\n\r\nServer
Error\r\n\r\n \r\n 401 - Unauthorized: Access is denied due to invalid credentials.\r\n You do not have permission to view this
directory or page using the credentials that you supplied.\r\n \r\n\r\n\r\n\r\n",
"innerError": {
"date": "2021-02-04T17:44:06",
"request-id": "7081a605-7db0-4312-a74a-8475aa8fdd3d",
"client-request-id": "7081a605-7db0-4312-a74a-8475aa8fdd3d"
}
}
}
At line:1 char:15

  • ... ebRequest = Invoke-RestMethod –Uri $uri –Method Get -Headers @{Author ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
  • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Any help would be appreciated!

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,635 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,548 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Deva-MSFT 2,256 Reputation points Microsoft Employee
    2021-02-05T16:25:09.87+00:00
    • The error is telling that you havent passed the correct credentials to perform the request. So re try the code with correct credentials and see if it works.
    • Just to isolate the issue you can repro the above graph api in Graph explorer or postman with right credentials and observe the results.

  2. Kathy Blasco 101 Reputation points
    2021-02-10T14:47:18.267+00:00

    Hi @Deva-MSFT
    I am not sure if my @ mention worked on my last comment? Please let me know next steps or thoughts?