I am searching a downloadable powerhsell module (using nuget) that contains a function like this :
function Invoke-SafeCommand {
param (
[ScriptBlock]$ScriptBlock
)
try {
& $ScriptBlock
}
catch {
Write-Host "An exception is thrown : $_"
exit 1
}
if ($LASTEXITCODE -ne 0) {
Write-Host "The command return this last exit code : $LASTEXITCODE"
exit $LASTEXITCODE
}
}
The goal is to check last exit code or exception of a called C# Console program. This script powershell is run on an azure devops pipeline, and I want the script to fails if the C# Console program fails. Regards Sybaris