# PowerShell 5.1 compatible. Designed for Nginx/Apache-style HTML directory listings. $LauncherVersion = 'v2026-10-30-02' $BaseUri = 'https://files.dayv.se/work/pwsh/' # Must end in / $UiWidth = 74 $PathSegments = @() try { $ProgressPreference = 'SilentlyContinue' } catch {} function TrimX { param($Text) if ($null -eq $Text) { return '' } return ([string]$Text) -replace '^[\s\xA0]+|[\s\xA0]+$', '' } function Write-Banner { param([string]$Title, [string]$Kind) $borderColor = 'DarkGray' $titleColor = 'Gray' switch ($Kind) { 'MENU' { $borderColor = 'Cyan'; $titleColor = 'Cyan' } 'RUN' { $borderColor = 'Green'; $titleColor = 'Green' } 'END' { $borderColor = 'Green'; $titleColor = 'Green' } 'WARN' { $borderColor = 'Yellow'; $titleColor = 'Yellow' } 'ERROR' { $borderColor = 'Red'; $titleColor = 'Red' } } $Title = TrimX $Title if ($Title.Length -gt $UiWidth) { $Title = $Title.Substring(0, $UiWidth) } $format = '{0,-' + $UiWidth + '}' Write-Host '' Write-Host ('╭' + ('─' * $UiWidth) + '╮') -ForegroundColor $borderColor Write-Host ('│' + ($format -f $Title) + '│') -ForegroundColor $titleColor Write-Host ('╰' + ('─' * $UiWidth) + '╯') -ForegroundColor $borderColor } function Write-Box { param([string[]]$Lines, [string]$Kind) $borderColor = 'DarkGray' $textColor = 'Gray' switch ($Kind) { 'MENU' { $borderColor = 'Cyan'; $textColor = 'Cyan' } 'RUN' { $borderColor = 'Green'; $textColor = 'Green' } 'END' { $borderColor = 'Green'; $textColor = 'Green' } 'WARN' { $borderColor = 'Yellow'; $textColor = 'Yellow' } 'ERROR' { $borderColor = 'Red'; $textColor = 'Red' } } $format = '{0,-' + $UiWidth + '}' Write-Host ('╭' + ('─' * $UiWidth) + '╮') -ForegroundColor $borderColor foreach ($line in @($Lines)) { if ($line -eq '__SEP__') { Write-Host ('├' + ('─' * $UiWidth) + '┤') -ForegroundColor $borderColor continue } $part = [string]$line if ($part.Length -gt $UiWidth) { $part = $part.Substring(0, $UiWidth) } Write-Host '│' -NoNewline -ForegroundColor $borderColor Write-Host ($format -f $part) -NoNewline -ForegroundColor $textColor Write-Host '│' -ForegroundColor $borderColor } Write-Host ('╰' + ('─' * $UiWidth) + '╯') -ForegroundColor $borderColor } function Get-ListingHtml { param([string]$Uri) $headers = @{ 'User-Agent' = 'Mozilla/5.0' 'Accept' = 'text/html,*/*' 'Cache-Control' = 'no-cache' 'Pragma' = 'no-cache' } try { return [string](Invoke-WebRequest -UseBasicParsing -Uri $Uri -Headers $headers -Method Get -ErrorAction Stop).Content } catch { return [string](Invoke-WebRequest -Uri $Uri -Headers $headers -Method Get -ErrorAction Stop).Content } } function Get-DirectoryItems { param([string]$Html) $items = @() $seen = @{} # A folder link ends in /; files do not. Handles extensionless script files too. # Accept only simple relative single-segment names to prevent traversing outside BaseUri. $links = Select-String -InputObject $Html -Pattern '(?is)href\s*=\s*["'']([^"''#?]+)["'']' -AllMatches foreach ($link in @($links.Matches)) { $href = TrimX $link.Groups[1].Value if ($href -match '^([a-zA-Z0-9._-]+)(/?)$') { $name = [string]$Matches[1] $isDirectory = ([string]$Matches[2] -eq '/') } else { continue } if ($name -eq '.' -or $name -eq '..') { continue } # Default PowerShell hashtables have case-insensitive keys. if (-not $seen[$name]) { $entry = [pscustomobject]@{ Name = $name IsDirectory = $isDirectory } $seen[$name] = $entry $items += $entry } elseif ($isDirectory) { $seen[$name].IsDirectory = $true } } $folders = @($items | Where-Object { $_.IsDirectory } | Sort-Object Name) $scripts = @($items | Where-Object { -not $_.IsDirectory } | Sort-Object Name) return @($folders + $scripts) } while ($true) { $currentUri = $BaseUri $folderDisplay = '/pwsh/' if ($PathSegments.Count -gt 0) { $relativePath = $PathSegments -join '/' $currentUri = $BaseUri + $relativePath + '/' $folderDisplay = '/pwsh/' + $relativePath + '/' } try { $html = Get-ListingHtml -Uri $currentUri $items = @(Get-DirectoryItems -Html $html) } catch { Write-Banner -Title 'ERROR: Cannot list folder' -Kind 'ERROR' Write-Host ("URL: {0}" -f $currentUri) -ForegroundColor DarkGray Write-Host $_ -ForegroundColor Red if ($PathSegments.Count -eq 0) { break } Write-Host 'Returning to parent folder.' -ForegroundColor Yellow if ($PathSegments.Count -eq 1) { $PathSegments = @() } else { $PathSegments = @($PathSegments[0..($PathSegments.Count - 2)]) } continue } Write-Banner -Title 'MENU - PowerShell Script Launcher' -Kind 'MENU' $menuLines = @() $menuLines += (' Launcher {0}' -f $LauncherVersion) $menuLines += (' Folder {0}' -f $folderDisplay) $menuLines += '__SEP__' $menuLines += '' $menuLines += ' Available items' if ($items.Count -eq 0) { $menuLines += ' (No files or folders found)' } else { for ($i = 0; $i -lt $items.Count; $i++) { $entry = $items[$i] if ($entry.IsDirectory) { $label = '[DIR] ' + $entry.Name + '/' } else { $label = '[SCRIPT] ' + $entry.Name } $menuLines += (' {0,2}. {1}' -f ($i + 1), $label) } } $menuLines += '' $menuLines += '__SEP__' if ($PathSegments.Count -gt 0) { $menuLines += ' Number/name = select 0/b = back r = refresh q = quit' } else { $menuLines += ' Number/name = select r = refresh q = quit' } Write-Box -Lines $menuLines -Kind 'MENU' $choiceRaw = Read-Host 'Run' $choice = TrimX $choiceRaw if (-not $choice) { continue } if ($choice -ieq 'q') { break } if ($choice -ieq 'r') { continue } if ($choice -eq '0' -or $choice -ieq 'b' -or $choice -eq '..') { if ($PathSegments.Count -eq 0) { Write-Banner -Title 'WARN: Already at root folder' -Kind 'WARN' } elseif ($PathSegments.Count -eq 1) { $PathSegments = @() } else { $PathSegments = @($PathSegments[0..($PathSegments.Count - 2)]) } continue } $picked = $null if ($choice -match '^\d+$') { try { $number = [int]$choice if ($number -ge 1 -and $number -le $items.Count) { $picked = $items[$number - 1] } } catch {} } else { $lookup = $choice -replace '/$', '' foreach ($entry in $items) { if ($entry.Name -ieq $lookup) { $picked = $entry; break } } if (-not $picked) { $hits = @($items | Where-Object { $_.Name -ilike "$lookup*" }) if ($hits.Count -eq 1) { $picked = $hits[0] } } } if (-not $picked) { Write-Banner -Title ("WARN: Invalid selection '{0}'" -f $choiceRaw) -Kind 'WARN' continue } # Names come only from validated relative links in the listing. if ($picked.Name -notmatch '^[a-zA-Z0-9._-]+$') { Write-Banner -Title 'ERROR: Unsafe item name' -Kind 'ERROR' continue } if ($picked.IsDirectory) { $PathSegments += [string]$picked.Name continue } $scriptUri = $currentUri + $picked.Name Write-Banner -Title ('RUN: ' + $folderDisplay + $picked.Name) -Kind 'RUN' Write-Host ('URL: {0}' -f $scriptUri) -ForegroundColor DarkGray Write-Host '' try { $scriptText = Invoke-RestMethod -Uri $scriptUri -Method Get -ErrorAction Stop if (-not ($scriptText -is [string])) { throw 'The URL did not return a text script.' } if ($scriptText -match '(?is)^\s*(?: