Omerp
Omerp

Reputation: 31

How to make an HTML GUI for PowerShell scripts?

I have an automation script for making new AD clients and Google mails. I would like to make a Web UI for this (HTML & CSS) so my team can log to this page and create from anywhere thy are.

How can I do it?

Is there a guide for making an HTML page connected to the PowerShell script?

Upvotes: 3

Views: 29017

Answers (6)

TottoB
TottoB

Reputation: 1

There is a Module called Pode and Pode.Web. Powerful Webserver based on Powershell and you can embed your Powershell Commands more informations you can find herePode and here Pode.Web

Upvotes: 0

kman
kman

Reputation: 2257

Shameless plug, but I've recently published a .NET5-based open source web app you might want to check out called SpecOps. It's intended to allow non-technical users the ability to run powershell scripts via a web-based GUI. You define your scripts and their input parameters in a json config file and it builds the GUI for your users on the fly.

Upvotes: 1

user2883951
user2883951

Reputation:

One option (of many) is to have Powershell host your HTML. Use the System.Net.HttpListener web listener, and answers requests based on what you are wanting to provide.

There is an article about building a web server with Powershell:
https://4sysops.com/archives/building-a-web-server-with-powershell/ https://www.powershellgallery.com/packages/HttpListener/1.0.2/Content/HTTPListener.psm1

When you have such low level control of the data scream, you can leverage the power of HTML into powershell.

Now, while this fits your question, this is pretty complicated (any time you have to develop in multiple languages at the same time -- HTML, Powershell, perhaps Javascript, etc), it can get complex in a hurry.

My suggestion is to make sure you really need the app your building to be web based.

If you just wanting GUI (and web is not a requirement) then this task would be far easier using the .NET forms ability of some of the other answers.

The powershell gallery link actually has a functional Powershell web server script in just under 175 lines (plus comments) that was originally written within Microsoft in 2014.

(The Microsoft code, in case it moves URL's, is called HTTPListener.psm1 so it can be found in a web engine search)

Upvotes: 2

Jay Adams
Jay Adams

Reputation: 2112

You can automatically generate a web front-end for PowerShell scripts using System Frontier. No HTML or server-side programming needed. You just create custom fields and assign them to command-line parameters.

You also get the benefits of having an access control layer in front of the scripts so non-admins can safely run the scripts with admin rights. The script output is also logged for auditing and data mining.

Upvotes: 0

softwaresupervillain
softwaresupervillain

Reputation: 59

Easiest might be to use a package like Jenkins that supplies a front end and has auth plugins already and can run powershell as well.

https://jenkins-ci.org/

There is a plugin for running powershell. https://wiki.jenkins-ci.org/display/JENKINS/PowerShell+Plugin

You can even tie it to Active Directory if you need. https://wiki.jenkins-ci.org/display/JENKINS/Active+Directory+plugin

Upvotes: 0

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200193

You use HTML GUIs (HTA) for VBScript and/or JavaScript. For PowerShell you use Windows Forms.

Add-Type -AssemblyName System.Windows.Forms | Out-Null

$form = New-Object Windows.Forms.Form
$form.AutoSize = $true
$form.AutoSizeMode = 'GrowAndShrink'

$form.Text = 'Window Title'

$label = New-Object Windows.Forms.Label
$label.Text = 'some text'
$label.AutoSize = $true
$form.Controls.Add($label)

$form.ShowDialog()

Upvotes: 0

Related Questions