Node JSPowerShell


Indeed, many moved to SNOW (servicenow) and enjoying it where in few customers are still using legacy products! In my work place snow is in proof of concept stage. Like many automation enthusiast I love to explore both REST and SOAP for solving customer requirements. In this article I will walk you through the steps to consume HPSM soap web service and publish it as REST end points.

If you aren’t new to PowerShell then you must have come across the Hey Scripting Guy Post – Use PowerShell to retrieve a weather forecast!  Yes, nothing much I will explain here and in fact I follow the same foot-steps for our PowerShell script to work with HPSM SOAP Web Service.

To begin with let us explore the PowerShell script to query incidents by ID. Here the ID is valid HPSM incident ID which has a format like IM12345

Cool! It works and for now don’t worry about performance. We have plenty of ways to fine tune this code which will be covered in my next upcoming blogs!

Node Application

It’s time for us to build a node application and distribute the solution as REST endpoint in on premise server. Yes, the HPSM web service we used is cloud hosted application and managed by third party vendor(s).

Using the built in module ‘child-process’ we called PowerShell.exe and passed the script file path as argument. That’s it! Rest is our fruitful result!

Output is as shown below

Using Express Framework

In the preceding example we successfully got the output in the console. Now, we need to get this working in our web server. After a bit of trial and error I figured out the easier method!

Browse to http://localhost:3000 to see the result


If you observed the code carefully we used static value for the incident ID. So we need to tweak our code little bit! Just parameterize your PowerShell script as illustrated below

And your server.js will look like below

It’s really simple! Browse to http://localhost:3000/incidentid/IM12345 to see the same result 🙂

Deploy it as Windows Service

For this I used qckwinsvc.cmd which is really very handy. After installing the qckwinsvc from npm globally – Just use it

Now our service is up and running


Leave a Reply

Your email address will not be published. Required fields are marked *