Read MSMQ Messages from PowerShell

This script dumps the contents of an MSMQ to the console. This one dumps the Journal contents of a private queue; of course you’ll have to adjust that line for your queue.

[Reflection.Assembly]::LoadWithPartialName("System.Messaging")

$queueName = '.\Private$\your.queue.name\Journal$';
$queue = new-object System.Messaging.MessageQueue $queueName;
$utf8 = new-object System.Text.UTF8Encoding;

$msgs = $queue.GetAllMessages();
$msgs | %{
    write-host $_.Id;
    write-host $utf8.GetString($_.BodyStream.ToArray());
};

 

This entry was posted in CodeMinder, MSMQ, PowerShell, Programming. Bookmark the permalink.