PowerShell Examples
Render an Aligned Plain-Text Table in PowerShell
Renders objects as a column-aligned plain-text table sized to the widest cell, ready for console or log output.
Base64 Encode and Decode UTF-8 Text in PowerShell
Encodes UTF-8 text to Base64 and decodes it back, catching malformed input and rethrowing with a clearer message.
PowerShell Input Validation with Field-Level Errors
Checks record fields and returns a validity flag plus per-field error messages instead of throwing on the first problem.
Build and Parse Query Strings with System.Uri in PowerShell
Encodes a hashtable into a percent-escaped query string and parses one back into a hashtable of decoded keys and values.
Parse JSON in PowerShell with Clear Error Messages
Wraps ConvertFrom-Json so empty input and malformed documents raise an error naming the offending line and position.
PowerShell HTTP GET JSON with a Hard Timeout
Performs an HTTP GET with a hard timeout, parses the JSON body, and raises a clear error on failure or empty content.
PowerShell Bounded Worker Pool with ForEach-Object Parallel
Runs a script block over many items with a fixed number of parallel workers and returns separate result and error lists.
Load and Validate Environment Config in PowerShell
Reads environment variables through a schema of defaults, required flags and validators, failing fast on bad config.
PowerShell Token Bucket Rate Limiter Class
Limits work to an average rate while allowing bursts up to a bucket capacity with a monotonic refill calculation.
PowerShell LRU Cache Class with Bounded Capacity
Provides a fixed-capacity cache that evicts the least recently used entry and refreshes recency on every read.
PowerShell Multi-Key Stable Sort with Nulls Last
Sorts records by one or more properties with a stable sort and pushes rows whose first sort key is null to the end.
Split a PowerShell Collection into Fixed-Size Batches
Splits any collection into arrays of a fixed size, keeping the final short batch, for batched API or database calls.
Stream a Text File Line by Line in PowerShell
Enumerates a text file lazily with File.ReadLines so very large files never have to be held in memory at once.
PowerShell Deep Clone and Recursive Merge of Hashtables
Creates a deep copy of a hashtable tree via JSON and recursively overlays another tree without mutating either source.
PowerShell Retry with Exponential Backoff and Jitter
Runs a script block with capped exponential backoff and jitter, retrying transient failures up to a fixed attempt limit.