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

3 thoughts on “Bulk Export of Exchange Mailboxes from a Collection

  1. Dean, thanks for the advice above. I want to export all mailboxes and propose to use the script with date filters as per your other page but want it to be dynamic in that I want to ;

    a) Prior to export, delete all PSTs in the export share folder
    b) Export all mailboxes with a dynamic date range ie all items within 30 days of today. So the script would have to change that date range every time the script is run

    Do you have this sort of thing coded as well?

    Thanks.

    David

    Like

  2. Hi David,

    In order to delete all the pst files in the export shared folder using my example you would need to run the below, to remove all files with the extension .pst from the shared folder \\Server\Share.

    Remove-Item “\\Server\Share\*.pst”

    To use a dynamic date range within a content filter I would use the below, to subtract a number of days from the current date using the AddDays method with a negative value, in this example 30.

    I found that the date format was required in the format ‘MM/dd/yyyy’ to process succesfully as a content filter.

    $Start = (Get-Date).AddDays(-30).toString(‘MM/dd/yyyy’)
    $End = (Get-Date).toString(‘MM/dd/yyyy’)

    New-MailboxExportRequest -Name $Mailbox.Alias -Mailbox $Mailbox.Alias ontentFilter {(Received -le $End) -and (Received -ge $Start)} -FilePath “\\Server\Share\” + $Mailbox.Name + “.pst”

    Hope this helps…

    Like

    1. Dean

      Thanks very much for your response and it does work, one mailbox at a time running a single command. However, as I’m in the UK and region is set to that, I’ve fallen foul of the US format scripting problem. So I left the script running only to return and find it still running and ended up with a 60GB dump of all psts.

      Is it possible to do this witihn the script;

      Set regional date
      ….execute psts with date range

      Set regional date back

      Cheers

      David

      Like

Leave a comment