We all aware of SELECT and TABLE tag in HTML. Many asks the same question “How to make my data dynamic?” Developers out there may have plenty of solutions. Me, as a IT PRO would like to demo using PSHTML and POLARIS (A PowerShell Way).
Show Process Information as Table and if Handles are greater than 200 set background color as RED.
PSHTML Code
html { head { title "Table Demo" } body -Content { table -ChildItem { th -Content "Name" th -Content "Handles" $processInfo = Get-Process | Select-Object -Skip 8 -Last 10 foreach ($process in $processInfo) { tr -Content { td -Content { $process.Name } if ($process.Handles -gt 200) { td -Content { $process.Handles } -Style "background-color:RED" } else { td -Content { $process.Handles } -Style "background-color:GREEN" } } } } } -Style "font-family:Candara" }
Polaris Code
Import-Module PSHTML -Verbose Import-Module Polaris -Verbose New-PolarisGetRoute "/TableDemo" -Scriptblock { $HTML = .\routes\TableDemo.ps1 $Response.SetContentType('text/html') $Response.Send($HTML) } Start-Polaris -Port 8080
Just browse to http://localhost:8080/TableDemo
So Cool Right? See how easy it is to use PSHTML with Polaris to build some thing we need in daily basis! Now, comes drop down that is select tag – Yes, it’s same logic
html { head { title "Table Demo" } body { hr h1 "Select Tag Demo" hr $Items = 1..10 selecttag -Content { foreach($Item in $Items) { option -Content $Item } } } -Style "font-family:Candara" }
Server.ps1 (Modifoed Code)
Import-Module C:\projects\PSHTML\PSHTML\PSHTML.psd1 -Verbose Import-Module Polaris -Verbose New-PolarisGetRoute "/TableDemo" -Scriptblock { $HTML = .\routes\TableDemo.ps1 $Response.SetContentType('text/html') $Response.Send($HTML) } New-PolarisGetRoute "/SelectDemo" -Scriptblock { $HTML = .\routes\SelectDemo.ps1 $Response.SetContentType('text/html') $Response.Send($HTML) } Start-Polaris -Port 8080
Enjoy PowerShell by using PSHTML and Polaris modules!