Created
October 8, 2018 13:55
-
-
Save rdpetrusek/ecc4993f11b97923e215b291b4870809 to your computer and use it in GitHub Desktop.
Send MSMQ Message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Reflection.Assembly]::LoadWithPartialName("System.Messaging") | |
| function WriteMessageToMSMQTrans($queueName, $message, $label) | |
| { | |
| $queue = new-object System.Messaging.MessageQueue $queueName | |
| $utf8 = new-object System.Text.UTF8Encoding | |
| $tran = new-object System.Messaging.MessageQueueTransaction | |
| $tran.Begin() | |
| $msgBytes = $utf8.GetBytes($message) | |
| $msgStream = new-object System.IO.MemoryStream | |
| $msgStream.Write($msgBytes, 0, $msgBytes.Length) | |
| $msg = new-object System.Messaging.Message | |
| $msg.BodyStream = $msgStream | |
| if ($label -ne $null) | |
| { | |
| $msg.Label = $label | |
| } | |
| $queue.Send($msg, $tran) | |
| $tran.Commit() | |
| Write-Host "Message written: " $message | |
| } | |
| WriteMessageToMSMQTrans "FormatName:DIRECT=OS:MACHINE_NAME\private$\QUEUE_NAME" $message "LABEL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment