Exchange export mailbox data in a specific date range

In a previous article I’ve explored how it is possible to use PowerShell to export content of a mailbox to a PST file for archiving or backup purposes, what has been described in the article is a full export meaning all mailbox data would be part of the PST file.

Sometimes we need to export mailbox content in a given time range for example to restore a set of lost messages from a backup or, as one of my customer used to do, to create an extra monthly archive of a specific service mailbox.

Luckily Exchange makes the mailbox export in a date range rather easy through the use New-MailboxExportRequest filters for example let’s assume we would like to export all messages in the info mailbox that have been received in December 2014 the command to be used would be similar to the following:

New-MailboxExportRequest -ContentFilter {(Received -lt '01/01/2015') -and (Received -gt '11/30/2014')} -Mailbox info -FilePath \srv-ex2k13mb01x$info_Export_December2014.pst

The above command will scan the info mailbox for any message matching the export date range we have defined, all messages received before January the 1st and after November the 30th, and export them to the defined PST stored on the X drive.

It is not over here, the -ContentFilter parameter has a lot of filterable properties that we can use to tweak our export command so that only interesting data is exported from the mailbox.

Let’s put aside the date range export example for a moment and let’s assume we want to export all messages sent to the Info mailbox from a user named HeloCheck the command we would use is similar to the following:

New-MailboxExportRequest -ContentFilter {ContentFilter {Sender -eq 'helocheck@helocheck.com'}} -Mailbox info -FilePath \srv-ex2k13mb01x$info_Export.pst

Taking the above example a step further let’s assume we want to export all messages with a specific subject line the command to be used would be similar the following:

New-MailboxExportRequest -ContentFilter {ContentFilter {Subject -like *Sales*}} -Mailbox info -FilePath \srv-ex2k13mb01x$info_Export.pst

As a last example let’s assume we want to export all messages sent in a date range the command would be:

New-MailboxExportRequest -ContentFilter {(Sent -lt '01/01/2015') -and (Sent -gt '11/30/2014')} -Mailbox info -FilePath \szhex04x$Info_Export_Send_December2014.pst

I think the above examples can serve as a good reference but as I already wrote the list of filterable properties is pretty long as you can see here.

Advertisements

2 thoughts on “Exchange export mailbox data in a specific date range

  1. This doesn’t work if you are using any other regional date format than the US format. In other words, this information is only useful in the US. I have tested this. I have tried setting the computer region to US and it still doesn’t work. It is probably to do with the internally stored date format. It surprises me that Microsoft don’t use ISO date format for all data storage. I have found this before with T-SQL, so it doesn’t surprise me.

    Like

    1. Hi Gavin,

      you’re (partially) correct and I will update the post as soon as I have a spare minute. I say partially as this can be used with other regional settings as well true enough you need to set the local to en-US this has to do with the way EMS interprets dates internally. Trust me on this as I main deal with CH-* (DE, IT, FR) locales and date is stored in the dd.mm.yyyy format.

      There is a more elegant way to workaround this without changing the local for the whole PC but I need to find a minute to document this.

      As soon as I have a minute I will document everything in a new post, I’ll drop you a reply as soon as that article is online.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s