I Multiply Happiness by Sharing!

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

Get-Service | Select-Object Name , DisplayName , Status -First 10

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)

tbody
tr
th Name
th DisplayName
th Status
each service in result
tr
td=service.Name
td=service.DisplayName
td=service.Status