2015/06/28

PowerShell - Using Office 365 REST API to get Calendar Events

A couple of weeks ago I was looking at a way to find the Calendar Events of an Office365 shared mailbox using PowerShell. Unfortunately I was not able to find a way to accomplished this task using the O365 Cmdlets. (Let me know in the comments if you know how...)

Update 2017/04/02: Support for timezone, Updated the function with error handler and some verbose messages. Added examples to retrieve the list of attendees emails

Update 2016/04/19: Function updated to support PageResult parameter

So I turned to the PowerShell Community and posted tweet about it.


Quickly I got an answer from @Mjolinor and @Glenscales who sent me some great stuff by using REST API. Thanks again guys!!

This is the example Glen sent me:
Invoke-RestMethod -Uri "https://outlook.office365.com/api/v1.0/users/sharedmailbox@domain.com/calendarview?startDateTime=$(Get-Date)&endDateTime=$((Get-Date).AddDays(7))" -Credential (Get-Credential) | foreach-object{ $_.Value }

This example shows how to list the calendar events for the next week. This is great and exactly what I needed, plus this run super fast compared to using the PowerShell module.

Of course you will need to have permissions on the specified mailbox.


Even though it show this as a CustomObject, the object type is Microsoft.OutlookServices.Event, see this MSDN page to find all the properties and methods available: https://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#EventResource