PowerShell script is quite handy when you are inside a windows environment. Sometime you might need to utilize existing powershell script in webMethods to suits your needs. This article is to share some ideas how to integrate PowerShell script into webMethods.
Run a Powershell script from the command line
The basic PowerShell tutorial: https://msdn.microsoft.com/en-us/powershell/scripting/core-powershell/console/powershell.exe-command-line-help. This gives basic idea how to run a Powershell script from the command line with parameter, here is the command syntax:
PowerShell[.exe] [-File <FilePath> [<Args>]]
Here is sample PowerShell script which search for a certain string in all files under a directory.
When invoke this script from command line, you need to add two parameters separated by space. Below is the return of script.
Execute OS command from webMethod Service
webMethods has provided a built-in java service that can execute command. This build-in service is access controlled which you need change OSCommand.cnf in WmPublic package before you execute this service. Alternatively, you can create your own java service which will give a bit more control of using it. Here is the sample code:
A real sample
I wrote a little PowerShell script to count number of hits on WebSphere web service. My WebSphere wrote all SOAP requests input and output into system.log file same as how webMethods generate server.log. PowerShell script was searching for a particular string in all log files within a folder. Then webMethods flow service collects the results and converts them into table.
Finally and most important, use Google Chart java script to build this colorful column chart
Copy the following files from MQ installation directory to WM integration server directory (IntegrationServer\lib\jars):
mqcontext.jar can be found in github.com while other jars provided by IBM by default installation.
Restart webMethods integration server.
Setup new TCPIP listener in MQ and start it.
Add JNDI service provider in MQ as JMS administered objects MQ
Provider URL: servername:port/SYSTEM.DEF.SVRCONN (port is the one created in step 3)
Initial Context Factory: com.ibm.mq.jsm.context.WMQInitialContextFactory
Required Libraries: mqcontext.jar
Connect this context factory.
Add MQ Connection Factory.
Make sure you select “Connection Factory” as type to view both Queue and Topic.
Add JNDI service provider in webMethods.
Under IS Admin – Setting — Messaging – JNDI Settings – Create JNDI Provider Alias.
Test JNDI Provider:
Add JMS Connection Alias in webMethods.
Under IS Admin – Setting — Messaging – JMS Settings – Create JMS Connection Alias.
JNDI Provider Alias: MQProvider (JNDI created in step 6)
Connection Factory Lookup Name: DEFAULT (Connection factory created in step 5)
Enable the JMS connection.
Send JMS message from webMethods to MQ use service pub.jms:send
Retrieve JMS message from MQ use JMS trigger