Forum Discussion

DavidE's avatar
DavidE
Contributor
7 years ago

Getting PowerShell Return Code

I am having trouble getting the return code from a powershell script when I execute an external powershell script as a file.  I looked at the documentation linked here, but it wasn't much help in ter...
  • DavidE's avatar
    DavidE
    7 years ago

    Unfortunately when executing the code as you provided from within TestComplete it does not work because you are executing the powershell script and requesting the error level in two different interpreters.  Not only that, but they are executing in parallel.

     

    What I ended up doing instead is this:

     

      strCMD = "powershell -file c:\test\Script.ps1"
      Set oShell=Sys.OleObject("WScript.Shell")
      rc=oShell.Run(strCMD, 0, True)
      Log.Message( "returncode=" & rc)
      

     

    rc is the Return Code from the script, and as you can see, we are waiting for the result from the oShell.Run command before continuing.