简体   繁体   中英

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!

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM