Utilizing the Workplace365/Trade 2016 REST API to entry Mailbox information utilizing PowerShell half 3

Utilizing the Workplace365/Trade 2016 REST API to entry Mailbox information utilizing PowerShell half Three In Half 1 of this persevering with sequence I appeared on the fundamentals of accessing a Mailbox utilizing the brand new REST api in PowerShell with Trade and in Half 2 accessing all of the mailboxes in a tenant as an Administrative software utilizing Certificates authentication. On this installment I’ve expanded the REST PowerShell module to embody a lot of the widespread information operations like enumerating Folder and Gadgets.

Getting a folder from Path

A typical factor you would possibly wish to do with a script that accesses a Mailbox is entry a non default folder eg say a folder {that a} consumer or software has created within the Inbox. To entry a folder with the REST api it’s good to first know the Id of that specific folder. With the WellKnownFolders in a Mailbox you should utilize the constants resembling Inbox,SentItems and many others however for non default folders you want some code that can first discover the Id of the Folder by looking for the folder in query in every of the dad or mum folders. I’ve added a perform within the Relaxation module referred to as Get-FolderFromPath which is able to take the Path of the folder you wish to entry and break down and seek for every of the folder within the Path after which return the goal Folder eg

Enumerating the Folders in a Mailbox

If you wish to enumerate all of the Folders in a Mailbox in EWS you can do a deep traversal with the  FindFolders operation which might return all of the folder paged in lot of 1000. With the REST API it’s good to traverse every of the ChildFolders individually to return all of the folders. With Trade in EWS there the place four totally different strongly typed Folder objects Mail, Duties, Contacts and Calendar, with EWS all of those the place returned with the FindFolder operation. Nonetheless with the REST API solely Mail Folders are returned. With the Calendar, Contacts and Duties folder it’s good to use the endpoints for these folder sorts which even have totally different permissions related. That is performed so you may have apps that may entry all of the calendar or contact folders in a Mailbox with out the necessity to have permissions to traverse the Mail folders (and through verse).So in case your migrating an current script its going to requires a barely totally different strategy from what you could have historically performed in different API’s when doing such a enumeration.

For enumerating all of the Folders in a Mailbox I’ve created the Get-AllMailFolders perform which additionally appends within the FolderPath as a price add eg

Enumerating Gadgets in a Folder

Upon getting retrieved a folder the following logical factor most individuals wish to do is enumerate the Gadgets in that Folder. To do that I’ve created just a few totally different capabilities within the module the most typical of these is the Get-FolderItems perform. This perform will both take the JSON Folder object or the trail of the folder you wish to entry after which return every of the Gadgets so you should utilize it like the next

this perform handles paging of the folder Gadgets in 1000 Merchandise pages with entails utilizing the @odata.nextLink return worth and $High and $Skip tokens from the response.

Enumerating All Gadgets in a Mailbox

One of many issues the REST API exposes simply that EWS did not is the flexibility to enumerate all Gadgets in a Mailbox utilizing the AllItems WellKnowFolder title. I’ve created a perform that exposes that endpoint for the AllItems folder eg

 Get-AllMailboxItems -MailboxName -AccessToken $tk

Enumerating Focussed Inbox Gadgets

The alternative to Litter in Workplace365 as a means of addressing Inbox overload in Trade is the Targeted Inbox which takes benefit of the speedy improvement of machine studying. From a programmatic standpoint the centered Inbox is uncovered as a Property InferenceClassification on a Message. So to indicate simply centered Inbox objects you should utilize the Filter token to question for these objects which can be simply equal to centered eg

“Inbox/messages/?`$select=ReceivedDateTime,Sender,Subject,IsRead,InferenceClassification`&`$Top=1000`&`$filter=InferenceClassification eq ‘Focused’”

I’ve created a perform referred to as Get-FocusedInboxItems for this which you should utilize like the next

Get the Mailbox GUID

One final thing that is useful typically when making an attempt to correlate information is the mailbox GUID for various customers. That is now extra simply out there within the REST api then it was in EWS utilizing the customers endpoint. I’ve put collectively a easy perform to make use of this referred to as Get-MailboxUser and it may be used like

The up to date REST module could be discovered on GitHub right here