PowerShell - Exit Code

$arg1Data = "someArgText";
$Proc = Start-Process -FilePath "some.exe" -ArgumentList @("-arg1:$arg1Data",'-someOtherSwitch','-anotherArg:someOtherText',"someStaticTextThatIsAnArg") -PassThru -Wait -NoNewWindow;
if($Proc.ExitCode -ne 0)
{
    Throw "Failed to execute with exitcode: $($Proc.ExitCode)";
}

With Splatting

$exe = "some.exe";
$arg1Data = "someOtherArgContent";

$cmdArgs = @(
    "-arg1:$arg1Data"
    ,'-someOtherSwitch'
    ,'-anotherArg:someOtherText'
    ,"someStaticTextThatIsAnArg"
);

$parms = @{
    "FilePath"=$exe;
    "ArgumentList"=$cmdArgs;
    "PassThru"=$true;
    "Wait"=$true;
    "NoNewWindow"=$true;
}

$Proc = Start-Process @parms;
if($Proc.ExitCode -ne 0)
{
    Throw "Failed to execute with exitcode: $($Proc.ExitCode)";
}

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-7.1

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_arrays?view=powershell-7.1

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.1

https://devblogs.microsoft.com/scripting/use-splatting-to-simplify-your-powershell-scripts/

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_remote_variables?view=powershell-7#using-splatting