How to REALLY export multiple messages from your Exchange 2010 queues.

So you may have an issue where you want to extract many (>1000) messages from your Exchange 2010 queue(s).

This could be because you want to play them in later via the replay folder after some outage or other scenario that may have caused transport to have issues (yes even in Exchange 2010 we sometimes have issues with mail flow, rare as they may be). You may not want to just mount the mail.que and have all these emails start being delivered right after some outage. It might be a better idea to stagger them in rather than let the flood gates open.

Either way you Bing “Export-Message” and find your way here- https://technet.microsoft.com/en-us/library/aa997214.aspx.

You soon realize that the example offered there does not seem to entirely work as expected in your environment (i.e. no messages get exported out to eml’s).

Well we are getting the TechNet article fixed but until then let me show you how to get all these messages out to eml files for suitable replay later.

First we will need to suspend the queue you would like to export the messages out from by issuing a Suspend-Queue –Id <Name_of_Queue> (you won’t need to suspend the poison queue as it is already in a suspended state).

As a side note I’d like to say here that if your messages are in the submission queue AND you are running exchange 2010 or exchange 2007 sp3 you are in luck. We finally allow you to export/remove/suspend messages in this queue. This was something that was impossible in earlier versions of Exchange 2007.

Ok back to our queue which should now be suspended.

Next we want to suspend the messages in this queue. Since there are more than 1000 we need to issue a Get-Queue –Id <Name_of_Suspended_Queue |Get-Message -ResultSize Unlimited |Suspend-Message.

We want the –ResultSize Unlimited since by default we will only retrieve the first 1000 messages.

Now this is where our article forgets to mention a few things.

First off we want to get all our messages from the queue we just suspended and put that result into an array like here-

$array = @(Get-Message -Queue unreachable -ResultSize unlimited)

Now we want to loop through that and send it to Export-Message and then send it to AssembleMessage (since we are on Exchange 2010 and using remote PowerShell now we need to pipe it to the AssembleMessage function because we don’t have direct access to the file system).

Also Export-Message wants you to declare the file name you are exporting the message to. This works for a single message but obviously for anything more than that it poses a problem. So we set a counter and increment it by 1 for each message and use that number as the file name.

Your next one liner will look like this-

$array | ForEach-Object {$i++;Export-Message $_.Identity | AssembleMessage -Path ("c:\exportfolder\"+ $i +".eml")}

 

So in the end you will get a bunch of .eml files in c:\exportfolder\ with names like 1.eml, 2.eml, 3.eml, and so on and so forth that you can then put into the Replay folder of your hub server when you are ready to let loose the backed up mail.