Hi there,
is it posible to use PowerShell to read/send message in a private MSMQ queue
?
Oriane
Hi there,
is it posible to use PowerShell to read/send message in a private MSMQ queue
?
Oriane
In message <DAAAA957-6CAA-4A5D-933C-0C334AB2334E@xxxxxx>, Oriane
<oriane@xxxxxx> writes
>Hi there,
>
>is it posible to use PowerShell to read/send message in a private MSMQ
>queue ?
There are no native cmdlets or providers to read/write to the MSMQ, so
in terms of out of the box features, the answer is no. I don't know the
implementation of MSMQ well enough, but it seems reasonable to assume
someone could write a cmdlet to add stuff to MSMQ.
--
Thomas Lee
doctordns@xxxxxx
MVP - Admin Frameworks and Security
There is no specific support in Powershell for MSMQ programming.
However since you can call essentially any .NET api from Powershell it may
be possible to get this to work if you are familiar with the System.Messaging
namespace.
I have not been able to get MSMQ installed correctly on the machine I am
using here, so take the following as hints rather than specific
instructions....
> [Reflection.Assembly]::LoadWithPartialName("System.Messaging")
> $queue = [System.Messaging.MessageQueue]::Create(".\private$\MyQueue")
> $message = new-object System.Messaging.Message.... and so on. Hope this helps.
> $queue.Send($Message)
"Oriane" wrote:
> Hi there,
>
> is it posible to use PowerShell to read/send message in a private MSMQ queue
> ?
>
> Oriane
>
>
Well, this piqued my interest so I installed MSMQ properly and got some basic
things to work from Powershell. Here are some notes and sample code.
# must load the Messaging assembly, it's not there by default
[Reflection.Assembly]::LoadWithPartialName("System.Messaging")
# create a new queue...
$qnew = [System.Messaging.MessageQueue]::Create(".\private$\queue1")
# ... or access an existing queue
$q1 = new-object System.Messaging.MessageQueue ".\private$\queue1"
# Create a message
$msg = new-object System.Messaging.Message "Into the Mystic"
$msg.Label = "A label"
# Send the message to the queue
$q1.Send($msg)
# Create and send as many more messages as needed...
# ... now to read some of them back again
# Messages in our queue will hold bodies of type string. Set up an array of
type
# names for the formatter (can there be more than one?).
$q1.Formatter.TargetTypeNames = ,"System.String"
# tell the queue we'd like to see some additional properties on
# messages we retrieve
$q1.MessageReadPropertyFilter.ArrivedTime = $true
$q1.MessageReadPropertyFilter.SentTime = $true
# Peek at the first message in the queue
$pkmsg = $q1.Peek()
# look at its properties..
$pkmsg
# Better have a timeout on peek and retrieve operations; if the queue
# is empty they will block the powershell session otherwise
$ts = new-object TimeSpan 30000000 # 3 seconds for example
$pkmsg = $q1.Peek($ts)
# Retreive and remove the first message in the queue
$rmsg = $q1.Receive($ts)
# look at its properties..
$rmsg.body
Into the Mystic
One quirk is that just typing
$q1
causes it to list the properties of (what appears to be) every message in
the queue, rather than the properties of the queue itself.
| Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| secure msmq | jimi hendrix | .NET General | 0 | 10 Dec 2008 |
| MSMQ Peek not working right | drez | PowerShell | 0 | 28 Feb 2008 |
| Vista/MSMQ question | ESmith | Vista General | 6 | 27 Aug 2007 |
| MSMQ Usage in PS | Andrew Burns | PowerShell | 2 | 02 Nov 2006 |
| Unattended installation of MSMQ | =?Utf-8?B?V0I=?= | Vista installation & setup | 0 | 03 Oct 2006 |