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