Opened 4 years ago

Closed 4 years ago

#320 closed testcase (fixed)

call a Powrshell script

Reported by: paetzold@… Owned by:
Priority: 1 Milestone:
Component: None Version: 0.3.6
Severity: Patches Keywords:
Cc:

Description

Hello,

I think that the example .ini file is wrong.
the line
check_test= cmd /c echo "scripts\ok.ps1" | powershell.exe -command -
have to be changed to
;check_test= cmd /c echo "scripts\ok.ps1;exit($lastexitcode)" | powershell.exe -command -

The reason is, that the servicestate ist alway "warning" and don´t get critical if the script ok.ps1 returns a value of 2.

If the powershell console returns the value to the calling instance than the state gets critical if the scripts returns with value 2.

Thomas Paetzold

Change History (1)

comment:1 Changed 4 years ago by mickem

  • Resolution set to fixed
  • Status changed from new to closed

Did a bit of digging and came up with this:

$host.SetShouldExit($exitcode)

or in your case:

$host.SetShouldExit(4)

Seems to work...

Interestingly enough doing exit does NOT work cf:

test.ps1
write-host "Test"
exit 4

Then:

C:\>powershell -noprofile -command "Write-output Test; exit 4"
Test
C:\>echo %ERRORLEVEL%
4

...

C:>powershell -noprofile test.ps1
Test
C:\>echo %ERRORLEVEL%
1


Michael Medin

Note: See TracTickets for help on using tickets.