Node JSPowerShell

Dynamic Table Rows and Data Using Node JS and PowerShell

This is just an exercise and not a great technical content in both NODE and PowerShell. I was helping my friend to achieve his needs in PowerShell and fixed all issues as planned. All happens over a coffee right? Here comes a question from him! How can I show data processed using PowerShell in fancy HTML over the browser? For our demo let’s show first 10 windows services! Our goal is to deliver the below shown output –

Name DisplayName Status
AdobeARMservice Adobe Acrobat Update Service Stopped
AdobeFlashPlayerUpdateSvc Adobe Flash Player Update Service Stopped
AgentService AgentService Running
AJRouter AllJoyn Router Service Stopped
ALG Application Layer Gateway Service Stopped
AppHostSvc Application Host Helper Service Running
AppIDSvc Application Identity Stopped
Appinfo Application Information Running
AppMgmt Application Management Stopped
AppReadiness App Readiness Stopped

All PowerShell lovers, as you guessed it’s first 10 services using the below snippets

Let’s keep the PowerShell part aside (Yeah, nothing tricky over there 🙂 ). We need to test the output by building dynamic table and for that a JSON format is required! So, let us use the sample JSON as illustrated below

Yes, I don’t want to build tables rows and map the values for table data! If we use ConvertTo-Html our goal is achieved in one go! So, to achieve the same using PUG over NODE JS use the below snippet (It’s a PUG code)

Here comes the server.js route – For now it’s on default “/” route

services is a JSON object assigned to the result variable. In PUG file we loop through items of JSON using each statement! Below illustrated image is our final result!

Full code is shown below – Please share your feedback for any corrections!

INDEX – PUG (Index.pug)

SERVER.JS (JavaScript)

Do you really need the PowerShell snippet used in ServiceInformation.ps1 ? Here it is and don’t forget to use the Compress switch!

Enjoy PowerShell!


Leave a Reply

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