×

Warning message

  • Cisco Support Forums is in Read Only mode while the site is being migrated.
  • Cisco Support Forums is in Read Only mode while the site is being migrated.

Is it possible to catch a PowerShell script output when an exit code is setted?

Unanswered Question
Jun 13th, 2012
User Badges:

Hi,


i'm using TEO 2.1.2 with the hotfixes from 1 to 12 already installed and i have a problem using the "Execute Windows PowerShell Script" in reading the output of a PowerShell script if an exit code is expressly setted . For example if i try to execute a script like:




the output given by the activity is only 0 (like the exit code).


This is a problem if i use a script with multiple exit codes corrisponding to different kind of situations and different outputs like the following:


if($flag -eq "0")


{


   Write-output "Hello"


   exit 0


}


elseif ($flag -eq "1")


{


   Write-output "Error 1"


   exit 1


}


else


{


  Write-output "Error 2"


  exit 2


}


or if i call an executable which exit codes i want to identify by a readable description.


Anyone knows a way to solve this issue?


Thanks a lot,

bye.


Giulio

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 0 (0 ratings)
Loading.
Christopher Roberts Wed, 06/13/2012 - 10:31
User Badges:
  • Cisco Employee,

I would write the exit code you want ... say

Write-Host -NoNewLine "Code 1"


then you can look at the Output property of the script and then use TEO's conditionals to spin off of that.


You should look to upgrade TEO as well.. we are on version 2.3 now as the most recent release with 2.3.1 due out shortly.


If you need more help directly with this you can open a TAC case and support can give a quick look, but most likely custom stuff would be directed to AS after TAC takes a quick look.


-Shaun Roberts

CPO/CIAC Support Lead

[email protected]

giuliodipace Wed, 06/13/2012 - 10:50
User Badges:

Thanks Shaun,

i was already looking toward this kind of approch, but i was also curious if there was a different way of doing this.

Anyway just a little annotation about your line of code, in Tidal 2.1.2 at least, Write-host doesn't work right, echo or Write-Output are fine but Write-host seems to be ignored. To the following script:



the output is



Maybe i'm missing something. Regarding an upgrade, as a devoloper i'd really like to try the improvement of the new version but this is not a decision I can make.


Thank you,

bye.


Giulio

Actions

This Discussion