Last active
November 17, 2023 18:10
-
-
Save dezren39/814da39a489b22433edbad899b753bd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set-StrictMode -Version Latest | |
$PSNativeCommandUseErrorActionPreference = $true | |
if ($PSNativeCommandUseErrorActionPreference) { | |
# always true, this is a linter workaround | |
$ErrorActionPreference = "Stop" | |
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop' | |
# sometimes you might need to update these to unicode or another format. | |
# unicode is the only normal one that stays the same between powershell 5 and pwsh core. | |
# utf8 may or may not have a bom. | |
# utf8nobom doesn't exist in powershell | |
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8' | |
$PSDefaultParameterValues['*:Encoding'] = 'utf8' | |
$utf8 = New-Object System.Text.UTF8Encoding($true) | |
[Console]::OutputEncoding = $utf8 | |
$OutputEncoding = $utf8 | |
} | |
function CheckLastExitCode { | |
param ([int[]]$SuccessCodes = @(0)) | |
if (!$?) { | |
if (-not (Test-Path variable://LastExitCode)) { | |
$LastExitCode = $LastExitCode | |
} | |
Write-Host "Last CMD failed $LastExitCode" | |
exit | |
} | |
if (-not (Test-Path variable://LastExitCode)) { | |
$LastExitCode = 0 | |
} | |
if ($SuccessCodes -notcontains $LastExitCode) { | |
Write-Host "EXE RETURNED EXIT CODE $LastExitCode" | |
exit | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment