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>]]
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