Release Automation

Expand all | Collapse all

Nolio Official KB: How do I Run Powershell comands in nolio?

  • 1.  Nolio Official KB: How do I Run Powershell comands in nolio?

    Posted Dec 18, 2013 04:26 PM
    Running PowerShell commands 
     
    PowerShell commands can be executed from within Nolio using the Run Command Line Action.
     
     The syntax would be 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 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:
     


  • 2.  RE: Nolio Official KB: How do I Run Powershell comands in nolio?

    Posted Dec 18, 2013 04:27 PM

    Please add more example, such as instead of call the script, how to add few lines of PowerShell codes within the Command Line, so we don't have to worry about locating files on the server to execute ps1. any ideas?