Exporting Mailboxes to PST (ExMerge) on SBS 2011 – Scheduled Task Part 1
May 10, 2011 1 Comment
So it looks like Wayne and Gagan beat me to posting the steps to exporting mailboxes out to PST files, the same functionality we used ExMerge for in the 2003 era, however something they didn’t publish was how to schedule it.
So before they do, i thought i would have a go.
Firstly to make it quicker for me to publish and increase the likelihood of beating them to it, i will assume you have read their awesome guide here..
So following on from them, let’s assume you want to schedule this to run each night, or weekly as a compliment to your already ‘robust’ backup routine, which i am sure is the corner stone of your foolproof disaster recovery plan.
You do have a plan don’t you?
Let’s examine the commands we need to run.
$Export = get-mailbox; $Export|%{$_|New-MailboxExportRequest -FilePath \\localhost\PST\$($_.alias).pst}
This command will execute to export all mailboxes on the server, and save them to a share called PST, inside which the mailboxes will be named alias.pst, from the screen shot below you can see my 3 mailboxes..
Now we are going to be scheduling this, so we wont be running it interactively, but we will want a log of what has occurred right?
so let’s append some text to our powershell command..
$Export = get-mailbox; $Export|%{$_|New-MailboxExportRequest -FilePath \\localhost\PST\$($_.alias).pst} | out-file c:\users\admin\mailbox-export-log.log
After a few seconds we are returned to a prompt..
Let’s open up the resulting file and see what we have got.
The resulting output is not really very friendly for a log file – yes we can see the exports are queued and we dont have any errors but it might be better if we could format the output a little neater.
If we change the syntax again slightly to include ‘format-list’ (fl for short) the output changes greatly.
$Export = get-mailbox; $Export|%{$_|New-MailboxExportRequest -FilePath \\localhost\PST\$($_.alias).pst} | format-list | out-file c:\users\admin\mailbox-export-log.log
Now this is probably too much information to review for a log file, so we now might want to narrow down what we are going to report.
Let’s now add some more syntax to our command, this goes in before we put the ‘format-list’ command or Fl for short.
$Export = get-mailbox; $Export|%{$_|New-MailboxExportRequest -FilePath \\localhost\PST\$($_.alias).pst} | select-object filepath, sourcedatabase, mailbox, status | format-list | out-file c:\users\admin\mailbox-export-log.log
This is much more manageable – we can see the path to the exported PST, we can see the source database (if we need it, if you are running more than one database) the actual mailbox and the request’s status.
You can choose which fields to include by looking in the left hand collum in the screen shots above to find the correct property name, then just include them in the syntax, for example to add the request guid and request name…
select-object filepath, sourcedatabase, mailbox, status, request guid, name |
What we can do now is run a second command to pull our results into a second log file.
get-mailboxexportrequest | select-object filepath, sourcedatabase, mailbox, status | fl | out-file c:\users\admin\mailbox-export-result-log.log
Hmm hold on – this is showing me EVERY mailbox export request ever. This is not ideal because our log file is going to be huge.
So what can we do?
As written in Wayne and Gagan’s article we can run this command to clean things up..
Get-MailboxExportRequest -Status Completed | Remove-MailboxExportRequest
If i press A to get rid of all the reports i am sent back to a PS prompt.
Now if i run my report again, i should get an empty log, because there are no mailbox export requests left on the system.
get-mailboxexportrequest | select-object filepath, sourcedatabase, mailbox, status | fl | out-file c:\users\admin\mailbox-export-result-log.log
So, the next time we run our export this log will be populated only with those particular export statistics, and in turn can be cleaned out by running the remove command.
In the next part of this article i will show you how to turn this into a scheduled task.
Hello Robert,
Thank you for the guide, the commandlet works perfectly, albeit terribly slow – maybe 100-200k/s, and this is on localhost. Is there any reason for such slowness ?