Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Return exitcode to cmd file from powershell (nested call)

$
0
0

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
}


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>