Skip to content

Instantly share code, notes, and snippets.

Created October 29, 2013 01:25
Show Gist options
  • Save anonymous/7207747 to your computer and use it in GitHub Desktop.
Save anonymous/7207747 to your computer and use it in GitHub Desktop.
Example of a .cmd file passing an argument to a .ps1 file and getting the error code back.
powershell -file c:\temp\script.ps1 -test:%1
echo %ERRORLEVEL%
//Calling batch file with argument, which gets passed to the ps1 script
c:\Temp>batch.cmd asdf
//asdf came from %1 argument to batch.cmd
c:\Temp>powershell -file c:\temp\script.ps1 -test:asdf
asdf
//%ERRORLEVEL% has exit code from ps1 file
c:\Temp>echo 5
5
//Add this to the end of the batch.cmd if you want error code passed to calling processes
exit %ERRORLEVEL%
Param(
[string]$test
)
write-host $test
exit 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment