r/PowerShell • u/Adventurous-Dog-6158 • Nov 26 '25
Microsoft Graph API - how to add calendar event via PowerShell
For testing, I'm trying to grant my Global Admin user account permission to its own calendar so I can test creating an event in it. I would use code based on this: https://learn.microsoft.com/en-us/graph/api/calendar-post-events?view=graph-rest-1.0&tabs=powershell.
When I connect via Connect-MgGraph, I see "Connected via delegated access using 14d82eec-204b-4c2f-b7e8-296a70dab67e" (this is the Microsoft Graph Command Line Tools enterprise app).
Some things I'm not clear on:
- For Microsoft Graph Command Line Tools enterprise app, I don't see any way to add Calendars.ReadWrite permission for user consent.
- Should I create a new app registration and grant it user consent for Calendars.ReadWrite?
- How do I, as a user, consent to allow the app permission to my calendar? I'm using my Global Admin user account to test.
- How do I run a PS script under the context of the new app so I can add an event to my calendar?
Eventually I want to grant my Global Admin user account permission to all mailbox calendars so I can add company holidays to them. Is there a simpler way to do this?
4
u/BlackV Nov 26 '25
I can see 0 ways this could possibly go wrong.......
same with this.....
is this not what a shared calendar would be for ? or a 365 group ? or teams somehow ?
3
u/inflatablejerk Nov 26 '25
Connect-mggraph -scopes calendar.readwrite.all
Or something along those lines.
2
u/ashimbo Nov 26 '25
For one-offs, using an individual account is fine, but for any automated process, you need to be using an app registration: https://learn.microsoft.com/en-us/entra/identity-platform/app-objects-and-service-principals
1
u/Adventurous-Dog-6158 Nov 26 '25
If this is helpful for anyone, below is what I got working so far.
Install-Module Microsoft.Graph.Calendar
Import-Module Microsoft.Graph.Calendar
# Connect via delegated access using 14d82eec-204b-4c2f-b7e8-296a70dab67e (this is Microsoft Graph Command Line Tools ent app). This is to my calendar only. As a Global Admin, there was a checkbox to "consent on behalf of your organization" which I did not select as I'm only focusing on my calendar for now.
Connect-MgGraph -Scopes Calendars.ReadWrite
$ParamsCalEvent = @{
}
strUserId = "bob@abc.com"
New-MgUserCalendarEvent -UserId $strUserId -CalendarId (Get-MgUserCalendar -UserId $strUserId).Id[0] -BodyParameter $ParamsCalEvent
---
# This returned 5 calendars. The default one is at the top, so use Id[0] to get that value, eg, (Get-MgUserCalendar -UserId $strUserId).Id[0].
PS C:\> Get-MgUserCalendar -UserId $strUserId
Name Id
---- --
Calendar AAMkAGI3NGYyNmQ2LTVjZTktNDdiYS1iNjVlLTdiZWE4NjllYTAyZABGAAAAAACLtE2XhukGQ6gsxf-fM5ZoBwBrUDxP-PV3Q6jFRoDyDCkuAAAAAAEGAABrUDxP-PV3Q6jFRoDyDCkuAAAvDUGsBBB=
Birthdays AAMkAGI3NGYyNmQ2LTVjZTktNDdiYS1iNjVlLTdiZWE4NjllYTAyZABGAAAAAACLtE2XhukGQ6gsxf-fM4ZoBwBrUDxP-PV3Q6jFRoDyDCkuAAAAAAEGAABrUDxP-PV3Q6jFRoDyDCkuAAAvDUGvCAA=
United States holidays AAMkAGI3NGYyNmQ2LTVjZTktNDdiYS1iNjVlLTdiZWE4NjllYTAyZABGAAAAAACLtE2XhukGQ6gsxf-fM6ZoBwBrUDxP-PV3Q6jFRoDyDCkuAAAAAAEGAABrUDxP-PV3Q6jFRoDyDCkuDAAvDUGwAAA=
United States holidays (1) AAMkAGI3NGYyNmQ2LTVjZTktNDdiYS1iNjVlLTdiZWE4NjllYTAyZABGAAAAAACLtE2XhukGQ6gsxf-fM8ZoBwBrUDxP-PV3Q6jFRoDyDCkuAAAAAAEGAABrUDxP-PV3Q6jFRoDyDCkuAEAw_uz6AAA=
Birthdays1 AAMkAGI3NGYyNmQ2LTVjZTktNDdiYS1iNjVlLTdiZWE4NjllYTAyZABGAAAAAACLtE2XhukGQ6gsxf-fM6ZoBwBrUDxP-PV3Q6jFRoDyDCkuAAAAAAEGAABrUDxP-PV3Q6jFRoFyDCkuAAAw_uz7AAA=
1
u/baron--greenback Nov 27 '25
This might help, I use it to log how I spend my time.
https://www.reddit.com/r/PowerShell/s/LIjfWe2U0d
1
u/nkasco Nov 28 '25
The place to start with Graph is always going to be authentication patterns. Specifically, ask yourself "how do I need this script to run, is it a scheduled automated job or is it an interactive script I will always launch"
That's critical because it completely changes the setup work on the Entra side. If you're launching it yourself, you're using delegated permissions and thus the account you're authenticating with needs access to do that thing in the first place. Conversely, if it's an automated job that runs non-interactively, you need to set up an AAD App Registration and will be using either a Client Secret or Certificate to authenticate (managed identity is also an option if running from an azure runbook)
Once you know that, the rest is honestly pretty simple to navigate typically.
1
u/HumbleSpend8716 Nov 26 '25
You need to just read up on graph api and permissions. Its a lot at first but just read and mess around with a test account. Google graph api permissions reference calendar.readwrite.all and start there