Absolute beginner bit off too much on his first step with PS and MSMQ..

Scenario:

Once in while, a message enters a specific transactional message queue on an application server.

If this message contains ‘xxx’, I have to delete it before it gets picked up and ‘poisons’ the treating process.

So far, I’ve got this:

[pre]

[System.Reflection.Assembly]::LoadWithPartialName("System.Messaging")

$queuePath = “.\private$\soapoutbound”

$queue = New-Object System.Messaging.MessageQueue $queuePath

foreach ($message in $queue.GetAllMessages()){

Write-Host (New-Object System.Text.UTF8Encoding).GetString($message.BodyStream.ToArray())

}


[/pre]

But it seems that I cannot use the -contains clause on this resulting array (will always return false).

Can anyone point me in the direction of a more example-based learning resource for this one?

Many thanks!

 

Where are you trying to use contains, can you pass little more details .

Apologies indeed… :slight_smile:

I will then try to concatenate the bodystream of ‘every’ message in the queue into one big String (usually only a few messages per minute max),

and use the -contain clause on that big String(UTF8Encoding). Still trying to find out how to do that.

If that comes out True, then I go looking for a way to delete the first message in the queue (because that one will be the offending one).

Anyway, that’s my ‘battle plan’.

The -contains comparison operator validates if a term is in an array returning a boolean result:

$colors = 'red','white','blue'

$colors -contains 'red' #true
$colors -contains 'darkred' #false, does not support wildcard search

The -like comparison operator validates a wild card term is found in a string retuning a boolean result

$searchTerm = '*xxx*'

'Our programming selection contains xxx material' -like $searchTerm #true