Skip to content
AyanmullickPublic

About

Initial PowerShell WASM experiment

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

PSWasm

PSWasm is a proof-of-concept WebAssembly runtime that runs browser-safe PowerShell-compatible scripts in static web pages. It does not require a build-time PowerShell-to-C# conversion step.

Quick Start

Try the hosted browser sample or edit the examples in CodePen.

To use PSWasm in your own page, add the hosted loader to a page served over HTTP:

<script type="pwsh">
$Name = 'PSWasm'
Write-Output "Hello $Name"
</script>

<script type="module" src="https://ayanmullick.github.io/PSWasm/app.js"></script>

PowerShell can also live in a same-origin .ps1 file. The web flavor includes DOM interaction and browser HTTP commands:

<script type="pwsh" src="./sample.ps1"></script>
<script type="module" src="https://ayanmullick.github.io/PSWasm/web/app.js"></script>

Inline and external scripts run in document order and share a runtime session. Browser fetch rules, including CORS, apply. For scripts that update the DOM directly, data-pswasm-output="none" hides the generated success-output box while preserving errors. See Browser Usage.

Build and Run Locally

Prerequisites: Git, the .NET 10 SDK selected by global.json, the wasm-tools workload, and the dotnet-serve tool for the local server. PowerShell 7 is required for the repository's .ps1 tooling. See setup and validation details.

Clone the repository, then publish and serve the browser sample:

git clone https://github.com/Ayanmullick/PSWasm.git
cd PSWasm
dotnet publish ./samples/BrowserHost/PSWasm.BrowserHost.csproj -c Release -r browser-wasm `
  -o ./.WorkDir/build/publish/BrowserHost /p:UseAppHost=false
dotnet serve --directory ./.WorkDir/build/publish/BrowserHost/wwwroot --port 5010 --address 127.0.0.1

Open http://127.0.0.1:5010/. Publishing restores dependencies and builds the sample; add --no-restore only when matching restore assets already exist. Stop the server with Ctrl+C. Generated build output stays under .WorkDir/build/.

To build only the runtime, without publishing the browser sample:

dotnet build ./src/PowerShell.Wasm/PowerShell.Wasm.csproj -c Release

Package for a Static App

Use the hosted loader above, or publish files to serve with your app:

pwsh -NoProfile -File ./tools/Publish-BrowserFlavors.ps1 -Flavor web

Copy app.js, app.d.ts, and _framework/** from .WorkDir/build/publish/BrowserFlavors/web/wwwroot/ together. The public tooling has two entry points:

The AzAuth flavor adds user-delegated Entra authentication and authenticated Azure REST calls. See Runtime Flavors and Payload Optimization and Azure Auth Cmdlets.

Supported Scope

The runtime includes PowerShell-style variables, arrays, hashtables, objects, operators, functions, control flow, splatting, pipelines, stream output, and a limited set of .NET helpers. Browser commands cover JSON/CSV/HTML conversion, DOM events and storage, HTTP requests, and optional Azure authentication.

Use & to invoke a script block or a registered command/function by name. See call-operator binding and scope for named arguments, switches, and splatting.

PSWasm does not provide the full desktop/server PowerShell host. Providers, native processes, profiles, remoting, jobs, unrestricted filesystem access, module autoloading, and arbitrary .NET reflection are outside its browser-safe scope.

Documentation and Contributing

Runtime verification, browser packaging, and DOM smoke checks are documented separately from the quick start.

License

PSWasm is available under the MIT License.

About

Initial PowerShell WASM experiment

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages