Ever needed to start a web server without installing IIS or a similar web server? Then the Webserver PowerShell Module could be something for you 🙂 In this blog post, I will show you how it works.
What does the Webserver Module do?
“Powershell WebServer is a module that starts a webserver (without the need for IIS). Powershell command execution, script execution, upload, download and other functions are implemented.
Powershell WebServer is is primarily intended as an example or base for own development. No multi threading, only one client at a time!
See Script Center version: Powershell Webserver.
Author: Markus Scholtes
Module version: 1.0.7 / 2024-02-03
Script version: 1.6 / 2024-01-31
The .Net class System.Net.HttpListener delivers a basic web service without the need to install a webserver (IIS) role. Since we can use it in C#, we can do it with powershell too (and even without pain).
There are several examples of powershell webservers in the internet, but for me it seems they all have the same origin. Thank you, original coder, whoever you are! My impulse to write a powershell webserver was a short but very impressing example on powershell.com (that unfortunately is no longer online).
The module WebServer implements a webserver with the following functions:
- a powershell command execution web form
- powershell script upload and execution (as a function)
- download files from the server
- upload files to the server
- script execution and embedded code with psp files
- make the webserver beep (to find servers in the datacenter)
- show webserver logs
- show server starttime and current time
- stop the webserver
- deliver static content based on the script’s directory if none of the commands above is requested
“
Source: https://github.com/MScholtes/WebServer
How to install
You can install it using the PSGallary using:
Install-PSResource -Name Webserver
Or, when you don’t have PSResourceGet available, you can use:
Install-Module -Name Webserver
After installation, you will have one Function available to you: Start-Webserver 🙂
Starting the webserver
After installing the module, you can use Start-Webserver without any Parameters to start a localhost webserver running on port 8080, which you can access using http://localhost:8080:

As you can see, after running Start-Webserver, the console shows that it started, and the items you clicked in the menu bar are displayed. (You can also see the history if you select “Web logs” in the menu bar)
You can start the webserver without any Parameters (Like the example above), but you can also use two Parameters:
- -BINDING, use this to start the webserver on another port. For example, Start-Webserver -Binding http://+:80/ to start the webserver and listen on all interfaces on port 80.
- -BASEDIR, use this to specify a specific folder for server static content. For example, Start-Webserver -Binding http://+:80 -Basedir c:\temp allows browsing http://localhost:80/index.html if index.html exists in c:\temp. (Making it a “real” web server 😉 )
Note: I had to start the webserver using Start-Webserver -Binding Start-Webserver -Binding http://192.168.168.3:8080/ to be able to reach it from another system. Using http://+8080 didn’t work.

Note: You may have to configure a firewall exception to allow access to the chosen port when using Windows, e.g., with:
netsh advfirewall firewall add rule name="Powershell Webserver" dir=in action=allow protocol=TCP localport=8080
Delete after halting the web server using:
netsh advfirewall firewall delete rule name="Powershell Webserver"
If you want to run the web server with a certificate (https), check https://github.com/MScholtes/WebServer/blob/master/https.md
Using the running website
After the web server is running, you can use it for the following things:
Command execution
Like a remote shell, you can enter commands to be executed on the machine running the web server. For example:


In the screenshots above, I entered Get-Process to show all processes, and after selecting Enter, it returned results. You can run all PowerShell Cmdlets and command-line tools just as you would locally. Things like Out-GridView will work, but only locally on that system and not remotely, of course 🙂 (It does start Out-GridView and will pop up on the system running the web server)
Execute script
This will allow you to run a script on the remote system, even with Parameters, if needed. For example:

After selecting Choose File, browsing to c:\scripts, selecting psif.ps1, and selecting Execute, the script ran, and its output is visible in the Terminal running Start-Webserver (or in the Web Logs section). The script psif.PS1 contained only one Write-Host command and was not displayed on the website. When using Write-Output, however, you do see it in the webpage itself:

Download file
Using this allows you to download files from the remote system. For example:

When specifying the path relative to the system you’re running Start-Webserver on, it will download the file to your system:

Upload file
And you can also upload a local file to the remote system. For example:

After selecting the local file about.md using the Choose File button, I specified the path relative to the system on which Start-Webserver is running. After selecting Upload, the file is visible on the path specified:


Web logs
This will show you output similar to the console output of Start-Webserver in your browser. For example:

Webserver start time
This will show you when Start-Webserver was executed:

Current time
This shows the time when the system ran Start-Webserver, which is convenient if you’re not sure about the timestamps in the log 😉 (Time Zone differences or no NTP sync, etc.)

Beep
Nice feature, not sure if it will work on systems without sound enabled. It should allow you to find the system if you’re not sure which system in your server room, or broom closet, is running Start-Webserver 😉

Stop webserver
This will shut down your Start-Webserver process.

More information
For more information about using Start-Webserver, including running it as a Scheduled Task, check https://github.com/MScholtes/WebServer.
Note: No authentication is required to access. Not for production, it’s suited for home/lab usage, etc.
Wrapup
And that’s how you use the Webserver module: a nice tool that makes it easy to run remote scripts or upload/download files. Have a lovely weekend!