Exploring PSHTML for Polaris – Yet another way to build forms using PowerShell!

In my last blog I shared about Building a simple form using PowerShell Polaris module. Where I used HTML and CSS from code pen sight – Now, I decided to go pure PowerShell way! Yes, let us use PSHTML module which is designed and developed by our well know PowerShell MVP Stéphane van Gulick. If you are a PowerShell user you must follow him on twitter @stephanevg.

Our objective is to collect user information and post to some system for processing. For our example collect user information and render it on browser using PSHTML and Polaris module!

Go Get the PSHTML and Polaris Modules and build your RESTful or HTML web forms using PowerShell


html {
    head {
        title "Home Page"
        link -rel "stylesheet" -href "home.css" -type "text/css"
    Body {
        hr {
            "Horizontal Line"
        } -Style "border-width: 2px"
        h1 {
            'PSHTML ♥ Polaris!' 
        } -Style "font-family: 'Candara';text-align:center"
        hr {
            "Horizontal Line"
        } -Style "border-width: 2px"
        form {
        } -action "/MyResponse" -method 'post' -target '_blank' -style "font-family:Candara" -Content {
            "First Name"
            input -type text "FN" -style "font-family:Candara"
            "Last Name"
            input -type text "SN"
            input -type submit "Submit" -style "font-family:Candara"


Import-Module Polaris -Verbose
Add-Type -AssemblyName System.Web
$Url = "http://localhost:8080"
New-PolarisGetRoute -Path "/MyRequest" -Scriptblock {
    $Html = .\form.ps1

New-PolarisPostRoute -Path "/MyResponse" -Scriptblock {
    $Body = [System.Web.HttpUtility]::UrlDecode($Request.BodyString)
    $Data = @{}
    $Body.split('&') | %{
        $part = $_.split('=')
        $Data.add($part[0], $part[1])
    $Response.Send(($Data | ConvertTo-Json))
Start-Polaris -Port 8080


Leave a Reply

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