MVP - Most Valuable Professional

Just can't get enough of IT

This blog is about mostly anything in IT. But the primary focuses are Microsoft technologies like Exchange Server, Microsoft 365, Microsoft Teams, and Cloud Security.

Exchange Server 2013Exchange Server 2016Description

This scripts helps to suspend all messages in an Exchange transport queue and to export all suspended messages to a given target folder.

The script uses the AssembleMessage cmdlet to properly export queued messages as .eml files.

Optionally, all exported messages can be removed from the transport queue. 


This script requires the GlobalFunctions module for logging.


# Export messages from queue MCMEP01\45534 to D:\ExportedMessages and do not delete messages after export
.\Export-MessageQueue -Queue MCMEP01\45534 -Path D:\ExportedMessages

# Export messages from queue MCMEP01\45534 to D:\ExportedMessages and delete messages after export
.\Export-MessageQueue -Queue MCMEP01\45534 -Path D:\ExportedMessages -DeleteAfterExport

Version History

  • 1.0, Initial community release
  • 1.1, Some PowerShell hygiene 


As always: Test and familiarize yourself with the script in a test or development environment.




Read More »
On February 17, 2016
0 Comment

When you encounter a situation where the transport queues are filling up or you just want to get messages out of a transport queue for further usage, you have to export the messages to the file system.

With Exchange 2007 you could easily utilize the Export-Message cmdlet to export suspended messages from a transport queue:

Get-Message -Queue MYSERVER\29489 | ?{$_.Status -eq "Suspended"} | Export-Message -Path D:\MessageExport

With Exchange Server 2010 or newer the Path attribute had been removed from the Export-Message cmdlet. The cmdlet now returns a binary object that needs to be assembled to a readable text message.

You can only export suspended messages, as the transport service might take precedence on non suspended messages. You can either suspend the queue or suspend single messages. The following example for Exchange Server 2010 or newer suspends the messages, but not the queue itself.

Identify the queue holding messages to be exported

Beispiel: Auflistung der Warteschlage auf Server MCMEP01

Get-Queue -Server MCMEP01
Identity                   DeliveryType Status MessageCount Velocity RiskLevel OutboundIPPool NextHopDomain
--------                   ------------ ------ ------------ -------- --------- -------------- -------------
MCMEP01\18                 SmtpDeliv... Ready  0            0        Normal    0              MXEDB19
MCMEP01\23                 SmtpDeliv... Ready  0            0        Normal    0              MXEDB08
MCMEP01\24                 SmtpDeliv... Ready  0            0        Normal    0              MXEDB01
MCMEP01\25                 SmartHost... Ready  3            0        Normal    0              []
MCMEP01\53                 SmtpDeliv... Ready  0            0        Normal    0              MXEDB03
MCMEP01\Submission         Undefined    Ready  512          0        Normal    0              Submission
MCMEP01\Shadow\3           ShadowRed... Ready  2            0        Normal    0    
MCMEP01\Shadow\4           ShadowRed... Ready  2            0        Normal    0    
MCMEP01\Shadow\5           ShadowRed... Ready  3            0        Normal    0    
MCMEP01\Shadow\6           ShadowRed... Ready  2            0        Normal    0    
MCMEP01\Shadow\15          ShadowRed... Ready  1            0        Normal    0    

Suspend all Messages in Queue MCMEP01\Submission

Get-Queue MCMEP01\Submission | Get-Message ResultSize Unlimited | Suspend-Message

Fetch all messages to an array and export all messages to the local file system. You can either export all messages by just enumerating the messages or by using the message subject as the file name. Using the message subject posed the risk that the subject might contain a character that is not allowed for file names.

$array = @(Get-Message -Queue MCMEP01\Submission -ResultSize Unlimited | ?{$_.Status -eq "Suspened"})

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

$array | ForEach-Object {$m++;$filename="E:\Export\"+$m+"_"+$_.subject+".eml"; Export-Message $_.identity | AssembleMessage -path $filename}

The messages exported to the local file system can now be copied to the Exchange Transport Replay folder, which exists on each Exchange Server having an Exchange 2010 Hub Transport role or Exchange 2013/2016 Mailbox role.

  • $exinstall\TransportRoles\Replay

After successful export of all suspended messages you want to delete the suspended messages from the queue. Ensure to use -WithNDR $false as otherwise all senders will receive a Non Delivery Report (NDR).

Get-Queue MCMEP01\Submission | Get-Message -ResultSize Unlimited | ?{$_.Status -eq "Suspened"} | Remove-Message -WithNDR $false

Messages saved to the Replay folder will be picked up the transport service. When a messages is picked up, the file extension changes to .TMP. You will not be able to delete a file at this point as the file is locked by the transport service. After a message file has been processed successfully, the file is deleted by the transport service. If there is any issue with the message file the file extension will change to .BAD.


Read More »