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

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.

Today, I’m going to talk about how to create new WMQ objects.

The commands all start with New-WMQ:


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

  CommandType     Name
  -----------     ----
  Cmdlet          New-WMQChannel
  Cmdlet          New-WMQListener
  Cmdlet          New-WMQNamelist
  Cmdlet          New-WMQProcess
  Cmdlet          New-WMQQueue
  Cmdlet          New-WMQService

PS C:\>  

To create a new local queue, you can open PowerShell and type New-WMQQueue


PS C:\> New-WMQQueue NEW_Q_NAME -QueueType Local

This might not be what you want – by default, New-WMQQueue will create this queue on every queue manager on your local system.

To limit this, you should specify which queue managers you want the command to run on. There are lots of ways to do this – I demonstrated several of these in yesterday’s post on getting WebSphere MQ objects to see what I mean. As a reminder, here are a few. Remember – these are all equivalent:


PS C:\> New-WMQQueue NEW_Q_NAME -Qmgr (Get-WMQQueueManager TESTQM) -QueueType Local
PS C:\> New-WMQQueue NEW_Q_NAME -QmgrName TESTQM -QueueType Local
PS C:\> New-WMQQueue NEW_Q_NAME (Get-WMQQueueManager TESTQM) -QueueType Local
PS C:\> New-WMQQueue -Name NEW_Q_NAME -QmgrName TESTQM -QueueType Local

Or if you want it split up across multiple lines:


PS C:\> $myQmgr = Get-WMQQueueManager TESTQM
PS C:\> New-WMQQueue NEW_Q_NAME -Qmgr $myQmgr -QueueType Local
     
    

Passing multiple queue managers to the command lets you create the new queue on multiple queue managers with a single command.


PS C:\> New-WMQQueue NEW_Q_NAME -QmgrName TES* -QueueType Local   
   

Obviously, QueueType isn’t the only property you can set. Tab-completion is supported for all New- commands, so you can type:


PS C:\> New-WMQQueue NEWQ2 -QmgrName TESTQM -QueueType Local -
    
   

After the hyphen (-), press tab. Keep pressing Tab to cycle through the possible attributes.


PS C:\> New-WMQQueue NEWQ2 -QmgrName TESTQM -QueueType Local -DefaultInputOpenOption
    
    

Properties that take strings can be types after the parameter. Put it in quotes if you want to use spaces:


PS C:\> New-WMQQueue NEWQ2 -QmgrName TESTQM -QueueType Local -Description "This is my description"
    
    

Properties that take numbers can just be provided as-is:


PS C:\> New-WMQQueue NEWQ2 -QmgrName TESTQM -QueueType Local -MaximumDepth 100
     
      

For properties that take constant values, type the name of the constant:


PS C:\> New-WMQQueue NEWQ2 -QmgrName TESTQM -QueueType Local -InhibitPut Inhibited
       
     

If you can’t remember the possible options are, you can type something wrong, and PowerShell will tell you what the valid options are:


PS C:\> New-WMQQueue NEWQ2 -QmgrName TESTQM -QueueType Local -InhibitGet CANTREMEMBER
New-WMQQueue : Cannot bind parameter 'InhibitGet'. 
Cannot convert value "CANTREMEMBER" to type "WebSphereMQ.MQC+InhibitGetTypes" due to invalid enumeration values. 
Specify one of the following enumeration values and try again. 
The possible enumeration values are "Allowed, Inhibited".
      
      

If you have gotten used to the runmqsc names for these attributes, these can also be used – the runmqsc names have been added to the cmdlets as aliases:


PS C:\> New-WMQQueue NEWQ2 -QmgrName TESTQM -QueueType Local -GET Inhibited
      
     

You can use as many attributes as you want


PS C:\> New-WMQQueue NEWQ2 -QmgrName TESTQM -QueueType Local -InhibitPut Inhibited -MaximumDepth 100 -InhibitGet Inhibited -TriggerType Every -Description mydescription -ProcessName THEPROC
       
    

The same approach works for other WebSphere MQ objects:


PS C:\> New-WMQChannel MYChan -ChannelType Sender -TransmissionQueueName XMITQ -ConnectionName "dlane.hursley.ibm.com(9294)"
PS C:\> New-WMQListener MYLstr -TransportType TCP -StartMode Qmgr -Port 9922
       
    

Other tricks

As with runmqsc, when you create an object, you can specify an existing object as a template with the “like” option:


PS C:\> New-WMQQueue MYNEWQUEUE -Like (Get-WMQQueue CLONEME_Q TESTQM)
     
    

You can change some attributes in the new copy by adding these to the New command:


PS C:\> New-WMQQueue MYNEWQUEUE -Like (Get-WMQQueue CLONEME_Q TESTQM) -Description modified
     
    

What’s next?

There’s still lots more that you can do. Tomorrow, I’ll write about how to search for 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.

Advertisements