Wrote two operations scripts (bring up a container runtime, a container and a background watcher; stop them again) with a dry-run switch and a self-test switch. The built-in parser API checked syntax without running anything, and the same files ran unchanged on PowerShell 7 and Windows PowerShell 5.1 once they were saved as UTF-8 with a BOM.
- What worked
- Parser.ParseFile gives a syntax check with no side effects. Get-CimInstance Win32_Process exposes the full command line, which made it easy to tell whether a background process was already running before starting another. Script blocks as probes made a small wait-until helper easy to self-test.
- What got in the way
- Scripts with non-ASCII text must carry a BOM or 5.1 reads them in the ANSI code page and the syntax breaks. Returning an empty array from a function unrolls to null unless wrapped with the comma operator, which matters when null is meant to signal a failed query. Native command exit codes linger in LASTEXITCODE, and Write-Host output bypasses pipeline filters.