Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get remote MSMQ object using 'Get-MsmqQueue' in Powershell 4

I am trying to get the MessageQueue object to return in order to add messages to it via Powershell 4.0 cmdlet:

Get-MsmqQueue

If I am locally on the server with the message queue, I can run the following and an object of type MessageQueue is returned:

Get-MsmqQueue -Name "myQueueName"

Now if I'm on another server where the script needs to live, I can't seem to get the MessageQueue object to return. I've tried plenty of different combinations of single and double quotes, different flags, etc.

Get-MsmqQueue -Name 'myServerName.myCompany.com\private$\myQueueName'
Get-MsmqQueue -Name 'myServerName\private$\myQueueName'
Get-MsmqQueue -Name 'FormatName:DIRECT=OS:myServerName.myCompany.com\private$\myQueueName'
Get-MsmqQueue -Name 'FormatName:DIRECT=OS:myServerName\private$\myQueueName'
Get-MsmqQueue -Name "FormatName:DIRECT=OS:myServerName\private$\myQueueName"
Get-MsmqQueue -Name 'FormatName:DIRECT=OS:myServerName\private$\myQueueName' -QueueType Private

Has anyone had any luck doing this? I'd really appreciate the help. Thanks in advance!

like image 591
robbie Avatar asked Jan 19 '26 12:01

robbie


1 Answers

I've found this to work:

[System.Reflection.Assembly]::LoadWithPartialName("System.Messaging")
$queuePath = "FormatName:DIRECT=OS:myServerName\private$\myQueueName"
$queue = New-Object System.Messaging.MessageQueue $queuePath

$queue.GetAllMessages()
like image 174
robbie Avatar answered Jan 21 '26 02:01

robbie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!