0
votes

I am simply trying to get a success or failure code out of a PowerShell script when run via VBScript with CreateObject("WScript.Shell").Run(strCMD, 0, True).

I thought Exit produced an exit code, but when I end my PS script with Exit 9 the value returned to the VBScript above is still 0.

The VBScript is:

strCmd = "powershell.exe -noLogo -executionpolicy bypass -file ""\\Mac\Px\Support\Px Tools\Dev 3.3.#\_Spikes\TestMessage.ps1"" -message:""I'm ALIVE"""
result = CreateObject("WScript.Shell").Run(strCMD, 0, True)
msgBox result
3

3 Answers

1
votes

Use Return "Your Value" in your ps script instead of Exit

Take care powershell will return anything what will be printed to the console

0
votes

Try this:

Set wso=CreateObject("WScript.Shell")
rc=wso.Run(strCMD, 0, True)
MsgBox "returncode=" & rc
0
votes

Just write

exit 123 

in TestMessage.ps1