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(<span class="str">"System.Messaging"</span>)

$queueName = <span class="str">'.\Private$\your.queue.name\Journal$'</span>;
$queue = <span class="kwrd">new</span>-<span class="kwrd">object</span> System.Messaging.MessageQueue $queueName;
$utf8 = <span class="kwrd">new</span>-<span class="kwrd">object</span> 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.