Update (13/12/2007): The contents of this post have since been largely superseded by the release of PowerShell cmdlets for WebSphere MQ.

A better way to do filtering

A follow-on post from WebSphere MQ scripting using PowerShell – part 2

In hindsight, my approach to filtering was too restrictive (filtering by name only). Instead, it would be better for the function to just return queue objects, and let the user use the built-in functions to filter on them as they want.

Display objects…

  • Choose which attributes you want to be outputted
  • Apply filters – return queues whose parameter(s) match certain filters (supporting complex queries with AND and OR)
  • Sort by a parameter

And do this for local or remote queue managers.

I’m leaving Display-WMQQueues as it is, and have started a new function – Get-WMQQueues – to do this.

This is much much better:

PS-WMQ DALE >  Get-WMQQueues | Select Name, CurrentDepth

Name                                                   CurrentDepth
----                                                   ------------
SYSTEM.ADMIN.ACCOUNTING.QUEUE                                     0
SYSTEM.ADMIN.ACTIVITY.QUEUE                                       0
SYSTEM.ADMIN.CHANNEL.EVENT                                        0
SYSTEM.ADMIN.COMMAND.QUEUE                                        0
SYSTEM.ADMIN.LOGGER.EVENT                                         0
SYSTEM.ADMIN.PERFM.EVENT                                          0
SYSTEM.ADMIN.QMGR.EVENT                                           1
SYSTEM.ADMIN.STATISTICS.QUEUE                                     0
SYSTEM.ADMIN.TRACE.ROUTE.QUEUE                                    0
SYSTEM.AUTH.DATA.QUEUE                                           54
SYSTEM.CHANNEL.INITQ                                              0
SYSTEM.CHANNEL.SYNCQ                                              0
SYSTEM.CICS.INITIATION.QUEUE                                      0
SYSTEM.CLUSTER.COMMAND.QUEUE                                      0
SYSTEM.CLUSTER.REPOSITORY.QUEUE                                   1
SYSTEM.CLUSTER.TRANSMIT.QUEUE                                     0
SYSTEM.DEAD.LETTER.QUEUE                                          0
SYSTEM.DEFAULT.INITIATION.QUEUE                                   0
SYSTEM.DEFAULT.LOCAL.QUEUE                                        0
SYSTEM.PENDING.DATA.QUEUE                                         0
TINY_QUEUE                                                       12

.

PS-WMQ DALE >  Get-WMQQueues | Select Name, CurrentDepth | Where { $_.CurrentDepth -gt 0 }

Name                                                   CurrentDepth
----                                                   ------------
SYSTEM.ADMIN.QMGR.EVENT                                           1
SYSTEM.AUTH.DATA.QUEUE                                           54
SYSTEM.CLUSTER.REPOSITORY.QUEUE                                   1
TINY_QUEUE                                                       12


.

PS-WMQ DALE >  Get-WMQQueues | Select Name, CurrentDepth | Where { ($_.CurrentDepth -gt 0) -and ($_.Name -like "*CLUSTER*") }

Name                                                   CurrentDepth
----                                                   ------------
SYSTEM.CLUSTER.REPOSITORY.QUEUE                                   1

.

You don’t need to compare against static values in your filters, either – for example:


PS-WMQ DALE >  Get-WMQQueues | Select Name, CurrentDepth, DepthHighLimit | Where { $_.CurrentDepth -gt $_.DepthHighLimit }

Name                         CurrentDepth            DepthHighLimit
----                         ------------            --------------
TINY_QUEUE                             12                        10

Any feedback on this new function would be gratefully received.

The code is below (note that it needs the code from yesterday’s post to work)

#
# Get queue objects from the queue manager
#
function Get-WMQQueues
{
    # display details of any WMQ errors encountered in this function
    Trap [IBM.WMQ.MQException] 
    { 
        Write-Error ("WMQ Exception: CC=" + $_.Exception.CompletionCode + " RC=" + $_.Exception.ReasonCode)
        continue
    }

    # if we have a connection to a queue manager...
    if ($Global:psWMQQmgrHandle -ne $null)
    {
        $qNames = Get-WMQQueueNames

        foreach ($queuename in $qNames)
        {
            $nextQueue = $Global:psWMQQmgrHandle.AccessQueue($queuename.Trim(),
                                                             [IBM.WMQ.MQC]::MQOO_INQUIRE)

            Write-Output $nextQueue
        }
    }
    else 
    {
        Write-Host "Not connected to a queue manager"
    }
}
Advertisements