Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Users might experience few discrepancies in Search results. We are working on this on our side. We apologize for the inconvenience it may have caused.
New Member

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

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

2 REPLIES
Cisco Employee

Is it possible to catch a PowerShell script output when an exit

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

shaurobe@cisco.com

--Shaun Roberts shaurobe@cisco.com CIAC Adoption Pilot Engineering Lead
New Member

Is it possible to catch a PowerShell script output when an exit

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

515
Views
0
Helpful
2
Replies
CreatePlease to create content