Part 1 of a series of posts on working with IBM WebSphere MQ from Windows PowerShell
Windows PowerShell is an object-oriented command line shell and scripting language, available for Windows XP, Windows Vista, and Windows Server 2003.
With the release of SupportPac MO74 (WebSphere MQ – Windows Powershell Library), Windows PowerShell can now be used to administer WebSphere MQ. In the next few posts, I’ll go through a few common WMQ system administration tasks in PowerShell.
For people new to Window PowerShell, I’ve added a few links to good resources for beginners at the end of my post.
Instructions on installing the PowerShell support for WebSphere MQ can be found in the MO74 documentation (pdf). I’ll be writing about what you can do once you’ve done that.
To start with – getting your WMQ objects.
The commands all start with Get-WMQ
:
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:\>
To get queues, you can open PowerShell and type Get-WMQQueue
PS C:\> Get-WMQQueue ...
I won’t show the output you get here, because it’s pretty big. Try it… you’ll get every property of every queue on every queue manager on your local system.
Remember that PowerShell is an object-oriented shell. Get-WMQQueue is getting you every queue object, and in the absence of any instructions to the contrary, is dumping all of them with all their properties on the console.
You can make this a little more friendly by choosing which attributes you are interested in:
PS C:\> Get-WMQQueue | Select Name, Description, CurrentDepth, MaximumDepth ...
Get-WMQQueue is still getting all queues, with all their properties, from all local queue managers. But this time, before sending them to the console, we pipe the objects through a Select command which selects the attributes we want – giving us a nice table of results.
This works in the same way for other WMQ objects. To get listeners:
PS C:\> Get-WMQListener | Select Name, TransportType, StartMode, Port Name TransportType StartMode Port ---- ------------- --------- ---- CENTLSTR TCP Qmgr 9282 SYSTEM.DEFAULT.LISTENER.LU62 LU62 Manual SYSTEM.DEFAULT.LISTENER.NETBIOS NetBIOS Manual SYSTEM.DEFAULT.LISTENER.SPX SPX Manual SYSTEM.DEFAULT.LISTENER.TCP TCP Manual 0 PS C:\>
You don’t have to get all objects into the pipeline… so if I wanted to look for listeners beginning with ‘C’:
PS C:\> Get-WMQListener C* | Select Name, TransportType, StartMode, Port Name TransportType StartMode Port ---- ------------- --------- ---- CENTLSTR TCP Qmgr 9282 PS C:\>
This is a short list because I’ve only got one queue manager on my box at the moment. What if I had more than one queue manager, but didn’t want to put objects from all queue managers in the pipeline?
There are so many ways to do this… here are a few:
Use positional parameters – first a listener name, then a queue manager. Get a handle to a queue manager and put it in a variable for use by Get-WMQListener
PS C:\> $myqmgr = Get-WMQQueueManager TESTQM PS C:\> Get-WMQListener C* $myqmgr | Select Name, TransportType, StartMode, Port Name TransportType StartMode Port ---- ------------- --------- ---- CENTLSTR TCP Qmgr 9282 PS C:\>
Use named parameters – but otherwise the same as above
PS C:\> $myqmgr = Get-WMQQueueManager TESTQM PS C:\> Get-WMQListener -Name C* -Qmgr $myqmgr | Select Name, TransportType, StartMode, Port Name TransportType StartMode Port ---- ------------- --------- ---- CENTLSTR TCP Qmgr 9282 PS C:\>
Use positional parameters – first a listener name, then a queue manager. Get the queue manager by including an inner Get-WMQQueueManager
command.
PS C:\> Get-WMQListener C* (Get-WMQQueueManager TESTQM) | Select Name, TransportType, StartMode, Port Name TransportType StartMode Port ---- ------------- --------- ---- CENTLSTR TCP Qmgr 9282 PS C:\>
Use a named parameter for the queue manager – get the queue manager by including an inner Get-WMQQueueManager
command again
PS C:\> Get-WMQListener C* -Qmgr (Get-WMQQueueManager TESTQM) | Select Name, TransportType, StartMode, Port Name TransportType StartMode Port ---- ------------- --------- ---- CENTLSTR TCP Qmgr 9282 PS C:\>
Use a named parameter for the queue manager, but this time use the QmgrName parameter, so Get-WMQListener
has to get a handle to the queue manager itself
PS C:\> Get-WMQListener C* -QmgrName TESTQM | Select Name, TransportType, StartMode, Port Name TransportType StartMode Port ---- ------------- --------- ---- CENTLSTR TCP Qmgr 9282 PS C:\>
Use positional parameters for both listener name and queue manager – again relying on Get-WMQListener
to get it’s own handle to the queue manager
PS C:\> Get-WMQListener C* TESTQM | Select Name, TransportType, StartMode, Port Name TransportType StartMode Port ---- ------------- --------- ---- CENTLSTR TCP Qmgr 9282 PS C:\>
Get the queue manager, and pass it down the pipeline to the Get-WMQListener
command
PS C:\> Get-WMQQueueManager TESTQM | Get-WMQListener C* | Select Name, TransportType, StartMode, Port Name TransportType StartMode Port ---- ------------- --------- ---- CENTLSTR TCP Qmgr 9282 PS C:\>
You don’t have to get just one queue manager. All of these examples would work if you used a wildcard to get multiple queue managers.
For example:
PS C:\> Get-WMQListener C* (Get-WMQQueueManager TEST*) | Select Name, TransportType, StartMode, Port Name TransportType StartMode Port ---- ------------- --------- ---- CENTLSTR TCP Qmgr 9282 CENT_ON_TESTQM2 TCP Manual 9283 PS C:\>
What’s next?
There’s lots more that you can do. Tomorrow, I’ll write about how to create WebSphere MQ objects in PowerShell.
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.
Recommended resources for PowerShell beginners
- Windows PowerShell Documentation Pack – the definitive documentation
- Windows PowerShell Owner’s Manual – task oriented beginner’s guide
- Next Generation Command Line Scripting – a webcast by the inventor of PowerShell
- Windows PowerShell book – free book available from msdn
- What can I do with Windows PowerShell? – sample scripts
- Mastering PowerShell in your lunchbreak – nice series of lessons
- An introduction to Windows PowerShell – PowerPoint presentation on using PowerShell
7 comments
Comments feed for this article
December 10, 2007 at 12:26 am
learning something new » Blog Archive » PowerShell for WebSphere MQ
[…] Update 2: I’ve made a start on describing how the PowerShell stuff can be used on the WebSphere MQ blog […]
December 11, 2007 at 12:03 am
Creating WebSphere MQ objects in the PowerShell ‘next-gen’ command-line « a Hursley view on WebSphere MQ
[…] Yesterday, I wrote about the support for using Windows PowerShell to administer WebSphere MQ systems, using the support introduced by SupportPac MO74, and demonstrated how to get your WMQ objects. […]
December 11, 2007 at 10:31 am
learning something new » Blog Archive » Explaining PowerShell for WebSphere MQ
[…] Getting your WebSphere MQ objects with PowerShell […]
December 12, 2007 at 1:49 am
Finding your WebSphere MQ objects with the PowerShell ‘next-gen’ command-line « a Hursley view on WebSphere MQ
[…] Monday, I discussed getting WMQ objects with PowerShell. Today, I want to talk in more detail about getting specific objects into […]
December 13, 2007 at 10:41 pm
WebSphere MQ scripting using PowerShell - part 3 « a Hursley view on WebSphere MQ
[…] April 18, 2007 in API, administration, tools, webspheremq by Dale Lane Update: The contents of this post have since been largely superseded by the release of PowerShell cmdlets for WebSphere MQ. […]
December 13, 2007 at 10:42 pm
WebSphere MQ scripting using PowerShell « a Hursley view on WebSphere MQ
[…] February 12, 2007 in API, webspheremq by Dale Lane Update (13/12/2007): The contents of this post have since been largely superseded by the release of PowerShell cmdlets for WebSphere MQ. […]
December 14, 2007 at 1:43 am
Looking for problems with your WebSphere MQ objects using the PowerShell ‘next-gen’ command-line « a Hursley view on WebSphere MQ
[…] my last four posts, I’ve given an introduction to how to use Windows PowerShell to administer […]