Using a Content Filter in Mailbox Export Requests

I recently wrote about performing a bulk export of mailboxes to PST from a collection (, in this script the entire contents of the mailbox was exported.

However, in instances where you only require to export a particular date range, you can use the Content Filter switch as part of the New-MailboxExportRequest cmdlet in Microsoft Exchange.

For Example, if I was looking to export mail items for the previous calendar month, I could run the following:

New-MailboxExportRequest -Mailbox <Mailbox Name> -ContentFilter {(Received -le '30/09/2013') -and (Received -ge '01/09/2013')} -FilePath \\Server\Share\Mailbox.pst

This would export all mail items which are greater than or equal to 01/09/2013 and less than or equal to 30/09/2013.

This can be particular useful, if performing a large mailbox export where the approach could be to perform an initial export of all the data and then run incremental style exports by using the content filter.

Bulk Export of Exchange Mailboxes from a Collection

I am currently looking at performing a bulk export of mailboxes from Exchange 2010 using the New-MailboxExportRequest cmdlet from a collection within a CSV file.

Firstly, I will want to remove any existing Mailbox Export Requests as I want to provide the status of the bulk export as the final step of the process with no previous history.

Get-MailboxExportRequest | Remove-MailboxExportRequest

Now, I want to generate the collection of mailboxes from reading the content of a file, which contains only the alias of each mailbox. In the below example, I am using the filename \\Server\Share\MailboxAlias.csv.

$Aliases = Get-Content "\\Server\Share\MailboxAlias.csv"

Now I want to request a mailbox export for each mailbox in the collection and export the PST with the Mailbox Name as the filename.  Therefore, the script block will firstly return all the mailbox attributes based on the mailbox alias name in the collection.

Also, by default Microsoft Exchange will auto generate 10 unique names for each mailbox export request. In this instance this is an insufficient amount to complete the bulk export. Therefore, we will specify the mailbox alias as the mailbox export request name.

ForEach ($Alias in $Aliases) 
$Mailbox = Get-Mailbox -Identity $Alias
New-MailboxExportRequest -Name $Mailbox.Alias -Mailbox $Mailbox.Alias -FilePath "\\Server\Share\" + $Mailbox.Name + ".pst"

At the final stage of the process I want to export the mailbox request status, therefore I will need to suspend the collection of this until all the export requests are reported as Completed.

I will perform this step by returning the mailbox export requests until all items are Completed and then export the mailbox request status to a CSV.

Do { 
$Queue = Get-MailboxExportRequest | Where-Object {$_.Status -ne "Completed"} 
Until ($Queue -eq $null)

Get-MailboxExportRequest | Export-Csv "\\Server\Share\GetMailboxExportRequest.csv" -NoTypeInformation