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

cls

$queueName = '.\Private$\NealTest'
$queue = new-object System.Messaging.MessageQueue $queueName
$utf8  = new-object System.Text.UTF8Encoding

$msgs = $queue.GetAllMessages()
 
write-host "Number of messages=$($msgs.Length)" 

foreach ($msg in $msgs)
  {
      write-host $msg_.Id
      write-host $utf8.GetString($msg.BodyStream.ToArray())
  }


Depending on how many times you wrote messages to the queue, the output will look something like this:

MSMQ_Read_Results

Filed under: MSMQ