PSHTML tip to validate the input text field(s) against JSON file

I got an interesting requirement through a Facebook ping, I took some time to think through it and decided to blog after finding a nifty PSHTML tip. Here is the requirement “I need to validate the input text field against the JSON file which has huge list of names. Can I do it using switch, for loop, for-each loop? I need check name by hard-coding it right?”

Well, the requester has a valid point. Why to hard code the values in switch statements? Why to loop through in first place? It’s PowerShell! So, its always IT Pro friendly.

Here comes the nifty tip! #PSHTML and #Polaris module.

$JsonContent = Get-Content -Path "C:\Temp\Users.json" | ConvertFrom-Json
$Html = form -action "/ValidUser" -method post -target _blank -Content {
input -type text -name text1 -Attributes @{pattern="$($JsonContent.Users.Name -join '|')"}
input -type submit -name submit1

Enjoy PowerShell – We have more tips in the pipeline!

Leave a Reply

Your e-mail address will not be published. Required fields are marked *