Skip to content
AyanmullickPublic

About

Initial PowerShell WASM experiment

Topics

Resources

Security policy

Stars

0 stars

Watchers

1 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.

Single-quoted strings stay literal; double-quoted strings expand variables and subexpressions. See strings and command arguments for quoting, escapes, and argument boundaries.

Numeric literals include hexadecimal/binary notation, exponents, size multipliers, and typed suffixes. See numeric literals for integer widths, decimal precision, and arbitrary-size integers.

Use [int]$Count = 1 to retain a variable's type across later assignments. See typed variables for conversion, arrays, scope, and assignment results.

Use $local:Name, $script:Name, $global:Name, or $private:Name to select variable scope explicitly. See variable scope for visibility, session lifetime, and variable-command -Scope arguments.

Functions also support local:, script:, global:, and private: declarations and calls. See function scope for visibility and shared-session behavior.

Use & to invoke a script block or a registered command/function by name, or . to run a script block/function in the current scope. return accepts expressions, commands, and pipelines. See binding, scope, and return behavior for the browser-safe subset.

Function parameters support multiline types and attributes, aliases, defaults, and ordered type constraints. See parameter declarations for binding and syntax rules.

Use [ordered]@{...} when dictionary insertion order matters; ordinary hashtables have no guaranteed enumeration order. See hashtables and ordered dictionaries for statement-valued entries, typed keys, indexing, and supported methods.

Array and string indexing supports negative positions and slices. See indexing and slices for result shape, missing values, and character results. Use ${item}?.Name or ${items}?[0] for null-conditional access, parenthesized when passed to commands. Inline block comments after member names are supported; see comments and line continuation for placement rules.

Use $Rows.Name or ('one','two').ToUpperInvariant() to access members across a collection. See collection member access for nested collections, result shape, and supported methods.

Use .ForEach() to transform items or access their members, and .Where() to filter, limit, or split a collection. See collection iteration and filtering for overloads, modes, and result shape.

Use Select-Object -First to stop a pipeline after the requested input, or add -Wait to consume the remaining input. See object pipeline commands for selection and completion behavior.

Use $_ or $PSItem for the current item in pipeline callbacks; param($Item) does not receive that item implicitly. See callback parameters, input, and scope.

Use $?, &&, and || to inspect execution status and recover from failures. See execution status and error handling for command boundaries, retained errors, and the supported subset.

Use typed catch clauses to select handlers, finally for cleanup, and throw to raise or rethrow errors. See error handling for supported exception types, handler selection, and browser-safe error descriptors.

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

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages