Part 3 of a series of posts on working with IBM WebSphere MQ from Windows PowerShell

In my last couple of posts, I’ve been demonstrating the support for using Windows PowerShell to administer WebSphere MQ systems, using SupportPac MO74.

On Monday, I discussed getting WMQ objects with PowerShell. Today, I want to talk in more detail about getting specific objects into PowerShell.

Recall that, to get objects, you use a Get-WMQ command.

PS C:\> Get-Command Get-WMQ*

  CommandType     Name
  -----------     ----
  Cmdlet          Get-WMQChannel
  Cmdlet          Get-WMQListener
  Cmdlet          Get-WMQNamelist
  Cmdlet          Get-WMQProcess
  Cmdlet          Get-WMQQueue
  Cmdlet          Get-WMQQueueManager
  Cmdlet          Get-WMQService

PS C:\>  

As discussed on Monday, by default, you get every property of every queue on every queue manager on your local system. There are two approaches to narrowing down the objects that you get:

Getting specified objects into the pipeline

You can limit the objects that Get-WMQ commands put into the pipeline by specifying object names and/or which queue managers to query. For example, identify specific objects:


or use wildcards to specify several:


You can do the same with the queue manager name:


Filtering – getting specified objects out of the pipeline

You can be more specific by piping the collection of objects through a Where command. For example, to get sender channels:

PS C:\> Get-WMQChannel | Where { $_.ChannelType -eq "Sender" }

You can do a variety of comparisons, including:

  • -eq – equals
  • -ne – not equal
  • -gt – greater than
  • -ge – greater than or equal
  • -le – less than or equal
  • -lt – less than
  • -match – match against a regular expression
  • -notmatch – inverse match using regular expressions
  • -like – perform pattern matching with wildcards
  • -notlike – perform inverse pattern matching with wildcards
  • -contains – determine elements in a group
  • -notcontains – determine excluded elements in a group

Comparisons can be combined in different ways, including:

  • -and
  • -or

So, to get all transmission queues which have been put-inhibited:

PS C:\> Get-WMQQueue | Where { $_.QueueType -eq "Local" -and $_.Usage -eq "Transmission" -and $_.InhibitPut -eq "Inhibited" }

To get all queues with more than ten messages in:

PS C:\> Get-WMQQueue | Where { $_.CurrentDepth -gt 10 }

Object attributes can be used on both sides of the comparison. For example, to get all queues which are 10 messages away from being full:

PS C:\> Get-WMQQueue | Where { $_.CurrentDepth -gt ($_.MaximumDepth - 10) }

As discussed on Monday, once you have the objects you want in the pipeline, you can pipe them to a Select command to get the attributes you want out of them:

PS C:\> Get-WMQQueue | Where { $_.CurrentDepth -gt ($_.MaximumDepth - 10) } | Select Name, CurrentDepth

This draws a table, with the name and current depth of all queues which are ten messages away from being full.

What’s next?

This is where PowerShell for WebSphere MQ is starting to get very powerful. You can use complex queries that are not just not possible with runmqsc. But there’s still lots more to cover. In tomorrow’s post, I’ll talk about modifying existing WebSphere MQ objects.

If you can’t wait till then, or want more examples, there is a “Cookbook for ‘PowerShell for WebSphere MQ'” – which contains dozens of worked examples for using PowerShell with your queue managers. Download the MO74 zip file and you will find the powershellcookbook.pdf included.

What do you think?

What do you think about this? Feedback on the SupportPac or the potential of PowerShell administration for WebSphere MQ, is very welcome. If you have any questions, I’d also be happy to try and answer them.