$ErrorActionPreference = "Stop"

try {
    # command
}
catch {
    Write-Error $_
    exit 1
}
