Friday, April 25, 2014

Oneliner Mailbox access with Powershell in Exchange Online using the oData preview

One of the things that was announced at MEC recently was Microsoft's Cloud first strategy with Exchange, which basically means that new feature will appear in Exchange Online first and then at some later date make their way into the OnPremise version of Exchange. One of these new cloud first features is the OData API for Mailbox data which is a REST based API for accessing mailbox data (as apposed to EWS which is a SOAP based API for accessing mailbox data). JSON and REST have become the standard for building WebAPI's over the past few years and every man and his dog (Google, Facebook,Twitter,Apple etc) are now using this so its exciting to see Exchange make this move.

If you want to find out more about it and you have a couple of hours to watch some good video's I would check the following two presentations from MEC and which will give you a good grounding in both oData  and also the new consent framework which is important if your building modern apps. 

One of the interesting things your can do with these REST API is using the Invoke-RestMethod cmdlet in Powershell v4 is now get access to Mailbox data with one line of code. Here are a few samples to wet your appetite and get you started (note this API is still in preview so this is subject to change/errors and bugs)

Show Unread Inbox Messages

  1. Invoke-RestMethod -Uri "`$filter=IsRead eq false" -Credential (get-credential) | foreach-object{$_.value | select Subject}  

Show Calendar Appointments for the next 7 days

  1. Invoke-RestMethod -Uri ("`$filter=Start le " + (Get-Date).ToUniversalTime().AddDays(7).ToString("yyyy-MM-ddThh:mm:ssZ") + " and End ge " + (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ssZ")) -Credential (Get-Credential) | foreach-object{$_.Value}  

Show Contacts

  1. Invoke-RestMethod -Uri "" -Credential (get-credential) | foreach-object{$_.value}  

There are lots more example of using the new REST commands at


J.S said...

I've searched everywhere and can't find a way to report on O365 calendars. I have to provide a report of meeting room calendars that has the details such as meeting organizer, attendees, start/end time, if it's recurring, etc.
I need to run this on a scheduled basis for many rooms. MS has stated it could be possible but they aren't sure and I've not found any way to do it after searching for a long time and trying several methods myself.
Can you assist? I have 2 other tasks as well that MS couldn't provide a solid answer on, there is one to be able to run a script and find out if an email has been "read" by one or more users based on the sender or subject as the search criteria, and then how to possibly gather a report on total number of emails sent to domains that are outside the company.

Any help is truly appreciated!
Thank You,

Glen Scales said...

I would use as a better based script rather then using the REST Api.

You won't be able to get the attendees from the Meeting rooms copy of the appointment the full attendee list will only ever be available from the organizer copy of the appointment (in office365 you could impersonate the organizer if you have impersonation rights and then get that).

2. You can search a recipient mailbox (probably eDiscovery would be best to find the message and see if it has been read) to see that but wouldn't be very reliable in an OnPrem network you would use ReadTracking but as far as I know that isn't available in o365 .

3. The Reporting Web Service would be where I would start. Short of that you can export the last 7 days of MailTrace logs and then work it from their I think products like promodag you can import and then do fancy report on these logs.