- Use `[System.Collections.Generic.List[object]]` and `.Add()` instead of `+=` on arrays — array `+=` copies the entire array on each append, making it O(n²).
- Use `ForEach-Object` pipelines for large datasets that don't fit in memory; use `foreach ($x in $list)` loops for small in-memory collections — the statement form is faster.
- Filter early in the pipeline with `Where-Object` before `Select-Object` or `Sort-Object` to reduce the number of objects processed downstream.
- Use `[System.Text.StringBuilder]` for building large strings in loops instead of string concatenation with `+` — each `+` creates a new string object.
- Avoid `Invoke-Expression` — it is slow and dangerous; use `& $scriptBlock` or direct cmdlet calls instead.
- Measure code blocks with `Measure-Command { ... }` before optimizing — PowerShell overhead is often in object creation, not in the algorithm itself.
- Use `-Filter` parameters (e.g., `Get-ChildItem -Filter '*.log'`) instead of piping to `Where-Object` when the provider supports native filtering — it is orders of magnitude faster.