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

Welcome Forums General PowerShell Q&A Absolute beginner bit off too much on his first step with PS and MSMQ..

This topic contains 3 replies, has 3 voices, and was last updated by

4 months, 2 weeks ago.

  • Author
  • #122771

    Points: 13
    Rank: Member


    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:

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

    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!


  • #122784

    Points: 1,628
    Helping Hand
    Rank: Community Hero

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

    • #122792

      Points: 13
      Rank: Member

      Apologies indeed.. 🙂

      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'.

  • #123111

    Points: 638
    Helping Hand
    Rank: Major Contributor

    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

The topic ‘Absolute beginner bit off too much on his first step with PS and MSMQ..’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort