Catch Powershell script errors in VBscript

I am calling Windows Powershell 2 scripts from VBscript using Shell command.

Set Shell = CreateObject("Wscript.Shell")
Shell.Run( "powershell.exe -noexit " & <PowerShellCommand>  )  

How can I catch errors/ exceptions from Powershell script and also pass these errors back to VBscript?

Thanks,
Naveed
jamke1Asked:
Who is Participating?
 
Chris DentPowerShell DeveloperCommented:

VbScript has no way of accessing that information directly I'm afraid.

A couple of ways to workaround this spring to mind.

The first is using the ErrorLevel environmental variable as discussed here:

http://thepowershellguy.com/blogs/posh/archive/2008/05/20/hey-powershell-guy-how-can-i-run-a-powershell-script-from-cmd-exe-and-return-an-errorlevel.aspx

The second, is to have PowerShell log its own errors to a file. How complex that gets depends on what your script does.

Chris
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.