You can use Microsoft Graph to get events from an Exchange Online mailbox. The Microsoft Graph PowerShell SDK makes this relatively easy to do with PowerShell.
Even when you use PowerShell, the API is Microsoft Graph. More complex implementations require some knowledge of Microsoft Graph. This article uses the Get-MgUserCalendarView cmdlet, so you should understand the basics of calendarView and the structure of the event resource.
First, connect to Microsoft Graph with Connect-MgGraph. See Getting started with the Microsoft Graph PowerShell SDK.
To connect with your own permissions, follow the “Try the Microsoft Graph PowerShell SDK with user permissions” section in that article and specify Calendars.Read in Scopes. To use your own permissions to get events from another user’s calendar that you can access, specify Calendars.Read.Shared in Scopes. To connect with application permissions, configure the Calendars.Read application permission for Microsoft Graph in the Azure portal.
After connecting, run the following command and specify the time range to retrieve:
1 | Get-MgUserCalendarView -UserId <user's UPN> -StartDateTime "<start date and time>" -EndDateTime "<end date and time>" -All |
Example:
1 | Get-MgUserCalendarView -UserId User01@contoso.com -StartDateTime "2021-09-01T00:00:00Z" -EndDateTime "2021-09-08T00:00:00Z" -All |
The output is not very readable as is, so format it for display. You can also reduce the amount of data sent over the network by requesting only the properties you need. For example:
1 | Get-MgUserCalendarView -UserId <user's UPN> -StartDateTime "<start date and time>" -EndDateTime "<end date and time>" -All -Property Subject, Start, End, Organizer, Attendees, Location | Select Subject, @{n="StartDateTime"; e={$_.Start.DateTime}}, @{n="StartTimeZone"; e={$_.Start.TimeZone}}, @{n="EndDateTime"; e={$_.End.DateTime}}, @{n="EndTimeZone"; e={$_.End.TimeZone}}, @{n="Organizer"; e={$_.Organizer.EmailAddress.Address}}, @{n="Attendees"; e={[string]::Join("; ", $(foreach ($attendee in $_.Attendees) {$attendee.EmailAddress.Address}))}}, @{n="Location"; e={$_.Location.DisplayName}} |
Example:
1 | Get-MgUserCalendarView -UserId User01@contoso.com -StartDateTime "2021-09-01T00:00:00Z" -EndDateTime "2021-09-08T00:00:00Z" -All -Property Subject, Start, End, Organizer, Attendees, Location | Select Subject, @{n="StartDateTime"; e={$_.Start.DateTime}}, @{n="StartTimeZone"; e={$_.Start.TimeZone}}, @{n="EndDateTime"; e={$_.End.DateTime}}, @{n="EndTimeZone"; e={$_.End.TimeZone}}, @{n="Organizer"; e={$_.Organizer.EmailAddress.Address}}, @{n="Attendees"; e={[string]::Join("; ", $(foreach ($attendee in $_.Attendees) {$attendee.EmailAddress.Address}))}}, @{n="Location"; e={$_.Location.DisplayName}} |
Example output:
1 | Subject : Test |
This retrieves and formats the subject, start and end times, organizer, attendees, and location. You can retrieve other properties in the same way.
Note
When this article was published, Get-MgUserCalendarView did not support the Prefer: outlook.timezone header. The current cmdlet has a -Headers parameter, so you can specify a time zone as follows. Without this header, the response times are in UTC.
1 | $headers = @{ |
For details, see the Get-MgUserCalendarView documentation.