Tuesday, September 08, 2015

Exchange EWS eDiscovery Powershell Module

eDiscovery is one of the more useful features introduced in Exchange 2013, and offers a quick and powerful way of Searching and reporting on Items in a Mailbox or across multiple mailboxes on an Exchange Server or in Exchange Online. In this post I wanted to rollup a few eDiscovery scripts I posted in the past to a more user friendly and expandable PowerShell module.

eDiscovery uses KQL (Keyword Query Language) to search indexed properties which are listed on https://technet.microsoft.com/en-us/library/dn774955(v=exchg.150).aspx . For doing quick reporting with eDiscovery you can tell Exchange to only return the number (and size) of the items that match your KQL query. Otherwise Exchange will return preview items (200 at time) which means the query can take some time to complete if your enumerating though a large result set.

I've tried to take a very modular approach with the code in this module to make it easier to extend

Permissions - The eDiscovery parts of this module requires the account that is running the script be a member of the Discovery Search RBAC role see . The code that gets the FolderPath does require the user running the script have rights to the Mailbox or EWS Impersonation rights.

Here are what the cmdlet's in the Module can do at the moment


This is just a generic cmdlet you can either enter in some KQL to make a query or entering in a Start and End Date to create a report of Items in a particular Date Range eg to show email from the Last month

Get-MailboxItemStats -MailboxName Mailbox@domain.com -Start (Get-Date).AddDays(-31) -End (Get-Date)

this will show results like

If you use the FolderPath switch this will instead show a folderlevel view of the results to get the folder list it must use the previewItems which are slower to retrieve eg

Get-MailboxItemStats -MailboxName Mailbox@domain.com -Start (Get-Date).AddDays(-31) -End (Get-Date) -FolderPath

would yield a results like


This is from one of my previous posts and returns a list of ItemTypes in a Mailbox, I've added a parameter so you can do a query on just one itemtype as well. So running it like this would yield a report of the Contacts in a Mailbox and where they are located


This lets you report on the From,To,CC and BCC fields of a message with Exchange these fields are indexed in the Participants property (as well as there own keywords for Recipients, to etc). Some cool things you can do with this is query Mailbox Traffic to and from a particular domain eg

If you then want to know more about one particular recipient type you can take the value in the Name property and use that in Get-MailboxItemTypeStats eg


One of the more useful things that you can do with this module is search and download attachments from a Mailbox using eDiscovery which you can't easily automate in the eDiscovery Console. So I've got a few different options for this. First I have


This works like the ItemType cmdlet in that it makes use of doing multiple OR queries on a list of attachment types. By default if you don't pass in an array of Attachmenttypes to query I have a list of 8 common types so it will produce a report like this

If you want to run a query based on one AttachmentType across folders you can use something like the following

Or limit it to one particular Attachment Name


You can download attachments using this cmdlet eg

If Exchange online if you have reference Attachments located in One Drive the module does have code to detect and download those using the sharepoint client libraries. You do need to change the version in

$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1


$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2015

I've put the Module up on GitHub https://github.com/gscales/Powershell-Scripts/tree/master/eDiscovery

You can download a copy of the script from here I've include a compile version of the latest version of the Managed API which include the update to process reference attachments.