Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Your First PowerShell Script: .ps1, Ways to Run It, #Requires, Comment-Based Help and pwsh vs powershell.exe
Called from inside PowerShell, a script runs in the same process in its own scope; called with pwsh -File, it runs in a new process and reports its result through the exit code, and Write-Error alone does not change that code. With Test-BookstoreHealth.ps1, which checks the Bookstore API, we show &, dot-sourcing, -File vs -Command, the shebang on Linux, #Requires, comment-based help, the differences between Windows PowerShell 5.1 and 7.6 LTS, and the BOM and CRLF traps.
Error Handling: Terminating and Non-Terminating Errors, $ErrorActionPreference, try/catch and Native Command Exit Codes
In PowerShell, $ErrorActionPreference = 'Stop' only stops on PowerShell errors; a failing exit code from a native command such as dotnet test also needs $PSNativeCommandUseErrorActionPreference = $true, otherwise publish runs even when tests break and the script exits with 0. We cover the two kinds of errors, try/catch/finally and trap, Write-Error vs throw, stderr and 2>&1, Set-StrictMode, the set -euo pipefail counterparts and a Bookstore build script that stops at the first failure.