Home » Blog » Running PowerShell From Within Nolio ASAP

Running PowerShell From Within Nolio ASAP

Nolio Logo

I often am either cc’ed on technical emails that are whizzing through Nolio’s global virtual collaboration platform (Google Apps) or intercept interesting discussions by quietly adding myself to the techies email groups. Either way, I convinced myself that some of the goodies I catch could be of interest to our customers, prospects, and friends.

So here’s the first catch-of-the-day; Mr. Benny sharing information about utilizing PowerShell exit codes from within Nolio Actions.

Warning: The sample provided is for demonstration purposes only and shouldn’t be taken to heart. Comparing two strings is done natively in Nolio with no coding or scripting.

Running PowerShell From With Nolio

PowerShell commands can be executed from within Nolio using the Run Command Line Action. The syntax would be something like this: powershell -command "&{.\yourpsfile.ps1 }". In the Nolio Action, you can use the expected return code field to let Nolio know what value should be expect from the script and act accordingly. The issue that Mr. Benny brings up is that the default return code of PowerShell scripts are always 0 (zero), even in the case where the script completely fails.  The reason being is that we’re apparently running the PowerShell script externally and the %errorlevel% is not passed through.

There is however a way to catch the real return code by adding appropriate exit handling in the script itself and using the following syntax to execute the PowerShell:

powershell -command "&{.\yourpsfile.ps1; exit $GLOBAL:LASTEXITCODE }"

Lets use the example myps.ps1 script:
PARAM ($Str1,$str2)
if ($str1.length -lt $str2.length){"string 1 length is less than string 2";exit 1}
if ($str1.length -eq $str2.length){"strings are equal";exit 2}
if ($str1.length -gt $str2.length){"string 1 length is greater than string 2";exit 3}

Wrapping all this up in a Nolio Action will look like this:

Nolio ASAP running PowerShell

And the results of that action will be:

Nolio ASAP running PowerShell - Result

Just remember, as mentioned in the warning at the beginning of this post, this is a pretty backward way of comparing two strings when your application deployment is done with Nolio. Just use the Compare Two Strings Action, plug in your parameters, and Bob’s your uncle.

Nolio ASAP Compare Two Strings Action

Read more about Nolio ASAP and application deployment automation platforms.



Related Posts

Back to top

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>