After publishing this post on Reddit PowerShell community we received great feedback about security. Currently Pglet service is in preview and is not recommended for use in production. We are working on built-in authentication/authorization functionality at the moment. It's going to be "Login with GitHub/Google/Microsoft" OAuth at first plus OpenID for any other providers.
Normally, to access computer via PowerShell you need to configure PowerShell remoting, open WinRM ports on firewall and, the most unpleasant part, add NAT rule on your router to expose a computer to the entire Internet.
So, how can I securely make a web UI for my script without any port opened on the firewall? I used Pglet - a free open-source service for adding remote UI to your scripts. Pglet acts as a relay between your script and a web browser. Your script "dials" the service and sends UI state updates while web users receive live page updates via WebSockets. Kind of Phoenix LiveView for PowerShell :)
To run the app you need to install pglet module:
The module works on Windows PowerShell on Windows 10 and PowerShell Core 6+ on Windows, Linux and Mac.
Here is how the app looks like:
Below is the entire program (GitHub):
In the program I used just a few Pglet controls: Textbox, Button, Spinner and Stack for the layout. Controls are organized into DOM and every time
page.update() is called its state is sent to Pglet service.
When you run the script, a new random URL is generated for your app and printed to the console:
At the very top of the program there is main entry point for the app:
-Name parameter is a page URL and
* means a randomly-generated string. You can add your own prefix to the random string or use another namespace, e.g.
If you want to tweak the app and test it locally, remove
-Web parameter and a local Pglet server will be started. There is also self-hosted Pglet server if you need more control.
That's it! More great examples are coming!