Running Get-MgUserDefaultCalendar in PowerShell gives Access is denied error

John Sparks 0 Reputation points
2024-06-21T12:20:45.4366667+00:00

Hi, I'm just starting with MS Graph PowerShell calls.

I've installed PS 7.4.3 and the Microsoft.Graph module.

I can use connect-mgGraph to connect and that connects OK as I get a MFA prompt and a welcome to Microsoft Graph!

When I run

get-mgUserDefaultCalendar -UserID "myemail@tenant.co.uk"

I get the error

Get-MgUserDefaultCalendar_Get: Access is denied. Check credentials and try again.

Status: 403 (Forbidden)

ErrorCode: ErrorAccessDenied

Can someone show me the steps needed to get approval for my PS script please? I get the feeling I need to somehow link my PS session to a app reg with more permissions?

thanks!

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,268 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,273 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vasil Michev 99,431 Reputation points MVP
    2024-06-21T16:41:44.8966667+00:00

    If you are running the cmdlet in the context of a given user, both the user permission and the permissions granted to the Graph SDK for PowerShell play a role. To check the latter, use the Get-MgContext cmdlet, then compare the output of the Scopes property against the permission requirements for the cmdlet/Graph endpoints you want to use.

    For example, a call against /users/{userId}/calendar endpoint requires at least the Calendars.ReadBasic permission (assuming you only want to check your own calendar). To make sure the cmdlet will be run with such permissions, run:

    Connect-MgGraph -Scopes Calendars.ReadBasic