I have a nested call (application > cmd file > powershell > start process powershell with file parameter), and I need to return the lastexitcode from the script back to the cmd file.
This is what the call from the .cmd file looks like, how can I pick up the lastexitcode in it? (please notice sysnative in windows path below, replace with system32 if testing locally).
C:\WINDOWS\sysnative\WindowsPowerShell\v1.0\powershell.exe "Start-Process C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell -ArgumentList '-ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File C:\Temp\EndJobCmd\Install.ps1' -Verb RunAs"
My function in the script looks like:
function SetLegacyExitCode { Param( [parameter(Mandatory = $true)] [System.Int32]$exitcode ) $host.SetShouldExit($exitcode) exit }