We are using vbscript in a Classic ASP page and in that vbscript I am calling Powershell using Wscript. I would like to check the return as it is meant to tell me whether the Powershell finished successfully of not. I have a return value in the Powershell script. I've tried both objShell.Run and objShell.Exec and neither one is allowing the Powershell return value through to my ASP page.
My question: how can I get the return values from Powershell?
VBScript follows:
'call PowerShell script with filename and printername and scriptname
strScript = Application("EnvSvcsPSScript")
Set objShell = CreateObject("Wscript.Shell")
dim strCommand
strCommand = "powershell.exe -file " & strScript & " " & strFileName & " " & strPrinterName
Set strPSReturn = objShell.Run(strCommand, 0, true)
response.Write("return from shell: " & strPSReturn.StdOut.ReadAll & "<br>")
response.Write("return from shell: " & strPSReturn.StdErr.ReadAll & "<br>")
Powershell script:
$FileName = $args[0]
$PrinterName = $args[1]
$strReturn = "0^Successful"
"Filename: " + $FileName
"Printer: " + $PrinterName
try
{
get-content $FileName | out-printer -name $PrinterName
[gc]::collect()
[gc]::WaitForPendingFinalizers()
}
catch
{
$strReturn = "1^Error attempting to print report."
}
finally
{
}
return $strReturn
THANK YOU!