Hi Oleg,
I have done some tests, and when a powershell script returns an error, it looks like the PowerShell Script action does not raise the error and the exit code is always 0, no matter what. Specially raising the error would be important in order to use the error-handling.
Thanks, Juanlu.
Powershell script errors not raising the error (exit code 0)
Re: Powershell script errors not raising the error (exit code 0)
This is behavior of Powershell application.
For example the script
always returns exit code 0. It doesn't matter if the file exists or not
If source file does not exist the script print error an message to output, but exit code is 0
You must forcibly change the exit code. For example like this:
If the file exists, 0 is returned. Otherwise, the script returns some integer value.
For example the script
Code: Select all
$dest ="C:\dest"
New-Item $dest -type directory -force
$source ="D:\somefile.txt"
Copy-Item $source $dest
If source file does not exist the script print error an message to output, but exit code is 0
You must forcibly change the exit code. For example like this:
Code: Select all
$dest ="C:\dest"
New-Item $dest -type directory -force
$source ="D:\somefile.txt"
Copy-Item $source $dest
# this does not work for some reason
# exit $LastExitCode
exit $error[0].exception.hresult
Oleg Yershov
Re: Powershell script errors not raising the error (exit code 0)
Another way:
You can save the output to variable and analyze the output text.
You can save the output to variable and analyze the output text.
Oleg Yershov
Re: Powershell script errors not raising the error (exit code 0)
Yes, that's what I ended up doing, analysing the output. Thanks anyway.