Office 365: Tracking last run times of the managed folder assistance / exchange life cycle.

In Office 365 the managed folder assistance is responsible for applying data retention policies to mailbox items.  For example, if you have a policy to purge items older that 90 days from deleted items – the managed folder assistant will process this information.

A question that sometimes arises is how can I track the last time the managed folder assistant processed a given mailbox.  Administrators of Exchange Online actually have an interface into this information.  Within the Exchange Online Management Shell there is a commandlet Export-MailboxDiagnosticLogs.  This commandlet will extract the details of the mailbox folder assistant process.  Here is an example:

PS C:\> Export-MailboxDiagnosticLogs -Identity tmcmichael -ExtendedProperties > c:\temp\output.txt

RunspaceId : 1290130b-c3af-49c2-a42c-b9dd98ed702d

MailboxLog : <Properties>


<Value>Timothy McMichael</Value>

LogName : ExtendedProperties

Identity : Timothy McMichael

IsValid : True

ObjectState : Unchanged

The output above is abbreviated as it is quite large.  One of the fields contained within the XML output is the ELCLastSuccessTimestamp.  Here is an example.

<Value>2/13/2019 12:20:18 PM</Value>


In this example the last time the mailbox folder assistant processed the given mailbox was on 2/13 at 12:20.  The commandlet itself is excellent for extracting single mailbox data.  What happens if we want to generate a report for multiple mailboxes?

If the need arises to query multiple mailboxes the following code can be utilized.

$mailboxes = get-mailbox -resultsize unlimited

$mailboxes |

% { $exportPath = "c:\temp\"+$_.alias+".xml" ;

    $exportPath ;

$xml = Export-MailboxDiagnosticLogs -ExtendedProperties -Identity $_.alias ;

$xml | Export-Clixml -Path $exportPath ;

$mailboxIdentity = ([Xml]$xml.MailboxLog).Properties.MailboxTable.Property | where { $_.Name -eq 'DisplayName' } ;

$mailboxIdentity.value ; $elcLastSuccessTimestamp = ([Xml]$xml.MailboxLog).Properties.MailboxTable.Property | where { $_.Name -eq 'ELCLastSuccessTimestamp' } ;

$elcLastSuccessTimestamp.value ; $object = new-object -TypeName PSObject ;

$object | Add-Member -MemberType NoteProperty -Name DisplayName -Value $mailboxIdentity.value ;

$object | add-member -memberType NoteProperty -name "Alias" -value $_.alias ;

$object | add-member -memberType NoteProperty -name "PrimarySMTPAddress" -value $_.primarySMTPAddress ;

$object | Add-Member -MemberType NoteProperty -Name ELCLastSuccessTimestamp -Value $elcLastSuccessTimestamp.value ;

$object | Export-Csv -Path c:\temp\output.csv -Append ; start-sleep -Milliseconds 500

In the first command we gather all of the mailboxes in the organization.  If your organization is large it is recommended to batch this to smaller numbers of mailboxes by performing a filter on the get-mailbox.  We then take the list of mailboxes and move it into a loop – where we process each mailbox by pulling the diagnostic logging.  With the diagnostic log pulled we extract pertinent information such as display name and last run time.  This is intentionally pulled from the XML to validate we are aligning the output to the correct export data.  An object is then built containing the information from the XML output and from the mailbox output stored in the array.  These objects are then exported to a CSV file.  The CSV file can be manipulated in excel.

Here is a sample CSV file:

#TYPE System.Management.Automation.PSCustomObject


"Alert Mailbox","alert","","2/12/2019 10:11:34 PM"

"AH","a-alias","","2/12/2019 11:55:21 PM"

"BM","b-alias","","2/13/2019 9:07:35 AM"

In the output directory specified the XML is retained in case further analysis is necessary.

This method utilizing powershell allows us to interrogate multiple mailboxes and determine the last time the managed folder assistant processed the mailbox.