Exchange – Using MailboxExportRequest ContentFilter for Date Queries

exchangeexchange-2013powershell

I am trying to export a mailbox to a PST. All email that was received before yesterday is what I am trying to export.

$y = ((get-date).addDays(-1)).ToShortDateString()
$exportRequest = New-MailboxExportRequest -ContentFilter {(Received -lt $y)} -mailbox userID -FilePath\\SHARED\folder\userID.pst

Something is not right here. I end up exporting the entire mailbox.

When I run a:

Get-MailboxExportRequest | Get-MailboxExportRequestStatistics | select ContentFilter

It says that my content filter is:

Received -ne $null

I am sure something is wrong with my syntax here, but I can't seem to get it.

Best Answer

It's a finicky syntax error and made worse by incorrect/unclear documentation. Please try the following --

$y = ((get-date).addDays(-1)).ToShortDateString()
$exportRequest = New-MailboxExportRequest -ContentFilter "Received -lt '$y'" -mailbox userID -FilePath \\SHARED\folder\userID.pst