DOM interaction sample

Enter a name and select Update text. PowerShell handles the form and updates the message.

Loading the PowerShell runtime and examples…

Explore the examples

Examples run on page load and share a PowerShell session. Expand a topic to see its output.

Browser informationCulture, dates, time zones, and available commands

Browser built-ins

Streams and expressionsOutput channels, operators, arrays, and hashtables

Warning and error messages in these examples are intentional. They demonstrate output streams and recovery.

Output streams

Expressions and collections

The left operand determines addition and comparison behavior. Ordinary arrays can hold mixed value types.

Null-conditional access

Parenthesize null-conditional expressions passed to commands. A null receiver skips index evaluation.

Numeric literals and precision

Use familiar numeric notation and explicit types for unsigned values, decimal scale, and arbitrary-size integers.

Strings and command arguments

Single quotes keep text literal. Double quotes expand values, and a bare prefix can join adjacent quoted text into one argument.

Collection member access

Read properties through nested collections, combine array-valued properties, and call supported methods on each result.

Collection iteration and filtering

Read members, convert values, select the first match, or split matching and remaining items.

Statement values and collection slices

Hashtable entries capture statement output. Slices keep their array shape, and strings expose character values.

Ordered dictionaries and typed keys

Ordered dictionaries preserve insertion order. Integer indexes select positions; an object-cast index selects a numeric key.

Browser HTTPWeb requests and JSON responses

This example calls the GitHub API. Its output depends on network access, CORS, and the service's rate limits.

HTTP requests

Variables and textVariables, automatic values, and regular expressions

The automatic-variable example deliberately writes an error to show how $? and $Error change.

Typed variables

A declaration keeps its conversion rule for later assignments. A failed conversion preserves the previous value.

Variable commands

Variable scope

A child scope has its own local values. Explicit scope selection can update the caller or the shared session root.

Automatic variables

Command status and error recovery

$? describes the last command or expression. Read it immediately; a successful expression resets it. A function's non-terminating error remains in $Error without making its caller fail.

Regular expressions

Functions and preferencesSplatting, stream preferences, and common parameters

Warnings and captured errors here are intentional; some messages are suppressed by the example itself.

Splatting

Preference variables

Common parameters

Control flowConditions, loops, functions, and error handling

If and else

Foreach loop

While loop

For loop

Switch

Functions and dynamic invocation

Function scope

Private functions are visible in their declaring scope; child scopes can still find an outer function with the same name.

Break, continue, and return

Typed catch handlers

Handle a specific exception before a general fallback. Cleanup runs after the selected handler.

Try, catch, rethrow, and finally

Pipelines and dataFiltering, JSON, CSV, formatting, sorting, and grouping

Filtering and projection

Pipeline callbacks use $_ for the current item; param defaults are evaluated for each item.

Selecting the first items

First stops the producer after two items. Wait keeps the same selection and lets all five items run.

JSON and CSV

Formatting, sorting, and grouping

DOM and shared sessionsDOM commands, the form above, and an external PowerShell file

DOM session commands

Interactive form

This script initializes the interactive form at the top of the page; it does not produce a separate output box.

Shared PowerShell session

External PowerShell file

Reuse and cleanup