apr 2 blog

PowerShell and MSMQ – Create XML message directly into MSMQ

By using the script below you can easy create a message directly into the message queue system in Windows – it’s great for debugging and testing of integrations is you need to test a Scribe DTS package


[Reflection.Assembly]::LoadWithPartialName("System.Messaging");
$queueName = '.Private$t_test2'; ##Define you MSMQ here!
$msgLabel = 'Message label'; ##Define your label here!
$queue = new-object System.Messaging.MessageQueue $queueName;
$utf8 = new-object System.Text.UTF8Encoding;
$tran = new-object System.Messaging.MessageQueueTransaction;
$tran.Begin();
$msgContent = '
    
        
        
    ';
$msgBytes = $utf8.GetBytes($msgContent);

$msgStream = new-object System.IO.MemoryStream;
$msgStream.Write($msgBytes, 0, $msgBytes.Length);

$msg = new-object System.Messaging.Message;
$msg.BodyStream = $msgStream;
$msg.Label = $msgLabel;
$queue.Send($msg, $tran);
$queue.Send($msg);

$tran.Commit();
Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+