This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| A pure PowerShell web server | |
| .DESCRIPTION | |
| A pure PowerShell web server proof of concept. | |
| This creates a simple web server that routes commands directly by their local path | |
| That is `/hello` would run the function `/hello` if it exists. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $JobName = "http://localhost:$(Get-Random -Min 4200 -Max 42000)/" | |
| $httpListener = [Net.HttpListener]::new() | |
| $httpListener.Prefixes.Add($JobName) | |
| $httpListener.Start() | |
| Start-ThreadJob -ScriptBlock { | |
| param($MainRunspace, $httpListener, $SourceIdentifier = 'http') | |
| while ($httpListener.IsListening) { | |
| $contextAsync = $httpListener.GetContextAsync() | |
| while (-not ($contextAsync.IsCompleted -or $contextAsync.IsFaulted -or $contextAsync.IsCanceled)) {} |