Exchange export Mailbox to PST with time frame

Hi there,

a quick one today. This is nothing new, but I needed it yesterday so decided to write it down.

Yesterday I exported a mailbox in Microsoft Exchange to PST. The file came out with 66GB which is way too large for Outlook. You can actually set registry entries to change the max allowed size for PST/OST files, but this didn’t work in my case. Always received an error message, telling me that I do not have enough system memory for that action.

So rather than export the whole mailbox in one go, I decided to split them into multiple parts. Separated by years.

Here are a few examples.

New-MailboxExportRequest

Open the Exchange Management Shell for the following lines.

First, we need to add the user to the “Mailbox Import Export” role.

PS /home/user> New-ManagementRoleAssignment –Role "Mailbox Import Export" –User "Administrator"

Close and reopen the shell.

Let’s start exporting.

  • Export received items after the 01/01/2022.
PS /home/user> New-MailboxExportRequest -ContentFilter {(Received -gt '01/01/2022')} -Mailbox <MAILBOX-NAME> -Name Name-of-the-Job -FilePath \\FQDN.domain.local\Exports\MAILBOX.pst
  • Export received and sent items after the 01/01/2022
PS /home/user> New-MailboxExportRequest -ContentFilter {(Received -gt '01/01/2022') -or (Sent -gt '01/01/2022')} -Mailbox <MAILBOX-NAME> -Name Name-of-the-Job -FilePath \\FQDN.domain.local\Exports\MAILBOX.pst
  • Export received and sent items before the 12/31/2021
PS /home/user> New-MailboxExportRequest -ContentFilter {(Received -lt '12/31/2021') -or (Sent -lt '12/31/2021')} -Mailbox <MAILBOX-NAME> -Name Name-of-the-Job -FilePath \\FQDN.domain.local\Exports\MAILBOX.pst
  • Export received and sent items between the 01/01/2022 and 02/01/2022
PS /home/user> New-MailboxExportRequest -ContentFilter {(Received -lt '02/01/2022') -and (Received -gt '01/01/2022') -or (Sent -lt '02/01/2022') -and (Sent -gt '01/01/2022'} -Mailbox <MAILBOX-NAME> -Name Name-of-the-Job -FilePath \\FQDN.domain.local\Exports\MAILBOX.pst

-lt (lesser-than-or-equal-to)
-gt (greater-than-or-equal-to)

Get-MailboxExportRequest

You can check the export jobs with the “Get-MailboxExportRequest” command.

PS /home/user> Get-MailboxExportRequest

To get a bit more information.

PS /home/user> Get-MailboxExportRequest | fl

To get the statistics.

PS /home/user> Get-MailboxExportRequest | Get-MailboxExportRequestStatistics | fl

Remove-MailboxExportRequest

If you want to remove all export jobs, you can use the “Remove-MailboxExportRequest” in combination with the “Get-MailboxExportRequest” command.

PS /home/user> Get-MailboxExportRequest | Remove-MailboxExportRequest

To remove a specific Export Job, you can either use “Remove-MailboxExportRequest” with the Job ID (you can get this with the “Get-MailboxExportRequest | FL” command) or you could narrow down the “Get-MailboxExportRequest” with a few parameters.

For example. You could use the “-Name” option to specify the job.

PS /home/user> Get-MailboxExportRequest -Name JobName | Remove-MailboxExportRequest

But, if you made the mistake of not naming the job (like me), then something like this could happen where you have multiple jobs with the same name. To focus it down, we can use the name and the status for instance.

And just pipe that into the remove command.

PS /home/user> Get-MailboxExportRequest -Name MailboxExport -Status Failed | Remove-MailboxExportRequest

That’s it.

Till next time.

Leave a Reply