Skip to content

Instantly share code, notes, and snippets.

@dezren39
Last active November 20, 2023 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dezren39/753fcb4be9ce23497e7e38fb87180c9c to your computer and use it in GitHub Desktop.
Save dezren39/753fcb4be9ce23497e7e38fb87180c9c to your computer and use it in GitHub Desktop.
Import-Lib.ps1
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 Test-LastExitCode {
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
}
}
function New-SymLink ($link, $target)
{
if ($PSVersionTable.PSVersion.Major -ge 5)
{
New-Item -Path $link -ItemType SymbolicLink -Value $target
}
else
{
$command = "cmd /c mklink /d"
Invoke-Expression "$command ""$link"" ""$target"""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment