FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

125 snippets foundClear filters
PowerShellGetting Started

Join an array into text

PowerShell: Join an array into text using PowerShell 7.

PowerShell✓ Tested
PowerShellStrings & literal text

Join several strings with a separator

PowerShell: The join operator returns one string from an input collection.

PowerShell✓ Tested
PowerShellGetting Started

Keep a dollar sign literal

PowerShell: Keep a dollar sign literal using PowerShell 7.

PowerShell✓ Tested
PowerShellFunctions & parameter validation

Keep function-local assignments separate from caller state

PowerShell: Ordinary function assignments create local variables rather than replacing the caller’s variable.

PowerShell✓ Tested
PowerShellFiles & paths

List files by extension

Enumerate regular files and return their names in order.

Get-ChildItem✓ Tested
PowerShellHashtables & object records

Merge configuration maps with override precedence

PowerShell: Copy defaults before applying override keys so the original remains unchanged.

PowerShell✓ Tested
PowerShellFile operations & integrity

Move a file into another directory

PowerShell: Move-Item transfers an existing file to the chosen destination directory.

PowerShell✓ Tested
PowerShellStrings & literal text

Pad a label with leading zeroes

PowerShell: Use a numeric format specifier to control the displayed width.

PowerShell✓ Tested
PowerShellArray operations

Pair corresponding values from two arrays

PowerShell: Check lengths before indexing to reject mismatched input collections.

PowerShell✓ Tested
PowerShellDates & numeric validation

Parse a hexadecimal integer

PowerShell: Convert.ToInt32 accepts an explicit base for a validated hexadecimal string.

PowerShell✓ Tested
PowerShellDates & numeric validation

Parse an integer without throwing on invalid input

PowerShell: TryParse reports conversion success separately from its output value.

PowerShell✓ Tested
PowerShellText & data

Parse JSON into an object

Access a named field in a JSON document.

JSON✓ Tested