Get-MgUserCalendarEvent: How to Fetch and Manage M365 User Calendar Events

This guide demonstrates how to use the Get-MgUserCalendarEvent cmdlet in Microsoft Graph PowerShell to retrieve calendar events. Learn how to fetch event details, filter by date, and export events with practical examples.

The Get-MgUserCalendarEvent cmdlet is a powerful tool within the Microsoft Graph PowerShell module that allows administrators to retrieve calendar events from a user's calendar. This article will guide you through the cmdlet's syntax, provide usage examples, offer tips, address potential errors with solutions, discuss use cases, and conclude with a summary of its utility.

Note: You need Calendar IDs to work with this cmdlet. Use Get-MgUserCalendar to get calendar IDs.


Cmdlet Syntax

Get-MgUserCalendarEvent -UserId <String> -CalendarId <String>
  • -UserId: Specifies the ID or user principal name (UPN) of the user whose calendar events you want to retrieve.
  • -CalendarId: Specifies the ID of the calendar containing the events.

Usage Examples

Example 1: Retrieve All Calendar Events

To get all events from a specific calendar, you can use the following command:

Get-MgUserCalendarEvent -UserId "user@example.com" -CalendarId "AAMkAGIAAA"

This command retrieves all calendar events from the specified calendar of the user.

PowerShell command output displaying all calendar events retrieved using Get-MgUserCalendarEvent for user@example.com.

Example 2: Exporting Calendar Events to a CSV File

To export calendar events to a CSV file for reporting or analysis:

Get-MgUserCalendarEvent -UserId "user@example.com" -CalendarId "AAMkAGIAAA" | Export-Csv -Path "C:\Reports\CalendarEvents.csv" -NoTypeInformation

This command exports all the details of each event to a CSV file. You get more details about each event – like created date-time, last modified date-time, attendee list, etc. - when you export them to a CSV file.

PowerShell script exporting calendar events to C:\R​eports\C​alendarEvents.csv using Get-MgUserCalendarEvent.

Example 3: Retrieve Calendar Events for a Specific Date Range

To fetch all events within a specific date range, use the -Filter parameter to filter based on start/dateTime and end/dateTime.

$UserId = "user@domain.com"
$StartDate = "2025-03-01T00:00:00Z"
$EndDate = "2025-03-31T23:59:59Z"
Get-MgUserCalendarEvent -UserId $UserId -Filter "start/dateTime ge '$StartDate' and end/dateTime le '$EndDate'"
PowerShell output showing calendar events filtered by date range using the Get-MgUserCalendarEvent cmdlet in Microsoft Graph PowerShell.

Cmdlet Tips

These handy tips will help you use the cmdlet more efficiently and avoid common pitfalls:

  • Always Specify -UserId: This is a required parameter and can accept both the UPN (user@example.com) and User ID (GUID format). Stick to UPN for ease.
  • Use Filtering with Caution: The $filter syntax must match supported properties (e.g., "start/dateTime ge '2025-04-01T00:00:00'"). Not all properties support filtering.
  • Pagination Considerations: Large mailboxes might require handling pagination using the -All switch or looping through result pages.
  • Timezone Awareness: The start and end times returned are in UTC by default. Convert them to the desired timezone in your output or script logic.
  • Use Select-Object or Format-List for Clean Output: To make results readable, use | Select-Object Subject, Start, End or | Format-List when testing in PowerShell.
  • For Multiple Users – Combine with Get-MgUser: Loop through user UPNs using Get-MgUser and call Get-MgUserCalendarEvent in a foreach loop for bulk reporting.
  • Error Handling Matters: Wrap your code in try-catch blocks and check for 404 Not Found errors—it often means the calendar is empty or permissions are missing.

Possible Errors & Solutions

Error Cause Solution
Invalid Filter Clause The -Filter parameter is incorrectly formatted or uses an unsupported property. Double-check the filter clause syntax. Ensure that the property you're filtering by is supported for filtering. Refer to the Microsoft Graph documentation for supported properties.
Get-MgUserCalendarEvent -UserId "user@example.com" -CalendarId "AAMkAGIAAA" -Filter "subject eq 'Meeting'"
Resource Not Found The specified -CalendarId does not exist or is incorrect. Verify that the -CalendarId is correct. Ensure that you have the necessary permissions to access the calendar and event. Calendars.Read or Calendars.ReadWrite is the required Graph API permission.
Get-MgUserCalendarEvent -UserId "user@example.com" -CalendarId "AAMkAGIAAA"
BadRequest The query contains an invalid parameter or unsupported query option. Review the command for any incorrect parameters. Ensure that properties like createdDateTime are valid for the -Filter parameter.
Get-MgUserCalendarEvent -UserId "user@example.com" -CalendarId "AAMkAGIAAA" -Filter "unsupportedProperty eq 'value'"


Use Cases

  • Audit Upcoming Meetings of Key Users: IT admins or compliance teams may need to check a user's future calendar for oversight or investigation purposes. This cmdlet allows retrieving meetings for the next day, week, or custom date range.
  • Fetch and Export All Events for Reporting: Easily pull all calendar events for a specific user and export the data to CSV for documentation, auditing, or report generation.
  • Search for Canceled or Declined Meetings: You can use filters to locate canceled meetings or identify users frequently declining invites. Helps team managers review meeting effectiveness.
  • Identify Calendar Overload or Conflicts: Retrieve all-day and overlapping events to see if users are overbooked or have scheduling conflicts. Useful for productivity optimization.
  • Retrieve Location-Based Meetings: Great for facilities or logistics teams to determine where resources (like meeting rooms) are being used.
  • Pull Subject and Attendee Info for Follow-Ups: Use this cmdlet to extract subject lines and attendee lists—ideal for sending follow-up emails or automating reminders after meetings.
  • Troubleshoot Calendar Sync Issues: If users report missing events or sync problems, you can query calendar data directly to verify what's present in their mailbox.
  • Track Specific Keywords or Project Meetings: Filter events with specific subject keywords (like “Budget”, “Security”, “All Hands”) for targeted insights into project meetings.

Frequently Askced Questions

1. What is Get-MgUserCalendarEvent used for?

Get-MgUserCalendarEvent is a Microsoft Graph PowerShell cmdlet used to retrieve events from a user’s calendar, including details like subject, attendees, and location.

2. How can I retrieve all events from a user’s calendar?

Use the following script to fetch all calendar events:

Get-MgUserCalendarEvent -UserId "<UserPrincipalName>" -CalendarId "<CalendarId>" -All

3. How can I filter events by date range?

Use the -Filter parameter to filter events by start and end date. Example:

Get-MgUserCalendarEvent -UserId "<UserPrincipalName>" -Filter "start/dateTime ge '2023-11-01T00:00:00Z' and end/dateTime le '2023-11-30T23:59:59Z'"

4. Can I export calendar events to a CSV file?

Yes, use this script to export event details like subject, attendees, and start time:

$Events = Get-MgUserCalendarEvent -UserId "" -All
$Events | Select-Object Subject, Start, End, Attendees | Export-Csv -Path "C:\Path\To\CalendarEvents.csv" -NoTypeInformation

5. What permissions are required to retrieve calendar events?

You need the Calendars.Read or Calendars.ReadWrite permission in Microsoft Graph PowerShell. Ensure appropriate permissions are granted in Azure AD.

6. Why does my Get-MgUserCalendarEvent command return an empty result?

If Get-MgUserCalendarEvent returns an empty result, here are some possible reasons and solutions:

  • No events exist in the specified timeframe
    If you've used a -Filter parameter with a date range, ensure that events actually exist within that range
    Try running Get-MgUserCalendarEvent -UserId user@domain.com -CalendarId <calendarid> filters to check if events are being returned at all.
  • The user doesn’t have calendar access enabled
    Confirm that the user has a Microsoft 365 license that includes Exchange Online, as calendar events are stored in Exchange.
    If the user is a guest, they might not have a calendar.
  • Incorrect permissions for Microsoft Graph API
    The Get-MgUserCalendarEvent cmdlet requires Calendars.Read or Calendars.ReadWrite permissions.
    Run Connect-MgGraph -Scopes "Calendars.Read" to verify permissions.

📅 Filter Events Within a Specific Date Range

You can filter calendar events by date using the -Filter parameter with start/dateTime and end/dateTime properties.

Make sure you use the correct datetime format (yyyy-MM-ddTHH:mm:ssZ) and wrap the property in quotes:
Get-MgUserCalendarEvent -UserId user@domain.com `-CalendarId <CalendarId> `-Filter "start/dateTime ge '2024-04-01T00:00:00Z' and end/dateTime le '2024-04-30T23:59:59Z'"
This helps retrieve only the events relevant to a given period without extra filtering in PowerShell.
💡 Retrieve Specific Event Details Using -Property

The Get-MgUserCalendarEvent cmdlet supports the -Property parameter to return only selected fields — improving performance and clarity.

For example, to fetch just the subject, location, attendees, and start time:
Get-MgUserCalendarEvent -UserId user@domain.com `-CalendarId <CalendarId> `-Property subject,location,attendees,start
This is useful for reporting, exporting, or when dealing with large sets of calendar data.

Access Events Calendar Using Admin Center

To access user calendar event using admin center, do the following:

  1. Go to Outlook app.
  2. Select Calendar >> Date & time >> View Calendar Events.
Microsoft 365 Outlook Calendar interface displaying event details, including date, time, and attendees.

Conclusion

The Get-MgUserCalendarEvent cmdlet is a versatile tool for accessing and managing user calendar events in Microsoft 365. By understanding its syntax, leveraging filtering and selection options, and addressing potential errors, administrators can effectively use this cmdlet to streamline calendar management tasks. Whether for routine event monitoring or detailed reporting, Get-MgUserCalendarEvent offers the flexibility and power needed for efficient calendar management.


Additional Resources:

Microsoft Graph PowerShell Get-MgUserCalendarEvent Cmdlet Documentation
Microsoft Graph PowerShell Module Documentation
Microsoft Graph API Documentation

Related Articles:

Using Get-MgDirectoryRole in Graph PowerShell
Using Get-MgUserLicenseDetail in Graph PowerShell
Using Find-GraphMgCommand in Graph PowerShell
Connect to Microsoft 365 Using PowerShell
How to Create Bulk Users in Office 365 Using Graph PowerShell?
Create Microsoft 365 Group Using Microsoft Graph PowerShell
Block Microsoft 365 User Using Microsoft Graph PowerShell
Assign Microsoft 365 License Using Graph PowerShell
Microsoft 365 User Management Using Graph PowerShell
Checking Group Membership in Microsoft 365
Bulk Assign Microsoft 365 License
Find Inactive Users in Microsoft 365
Using Powershell Graph Search Query
Using Powershell Graph Filter Query
Using Where-Object In Graph PowerShell
Using Expand Property In Graph PowerShell
Using Select Object In Graph PowerShell
Using -Contains Operator In Graph PowerShell
Add User to Multiple Microsoft 365 Groups Using Graph PowerShell
Get Microsoft 365 User Location Using Graph PowerShell
Import Microsoft 365 Groups from CSV File Using Graph PowerShell
Microsoft 365 Group User Import Using Graph PowerShell

© m365corner.com. All Rights Reserved. Design by HTML Codex