#199 closed defect (fixed)
Powershell scripts fall in timeout
| Reported by: | ebollengier@… | Owned by: | mickem |
|---|---|---|---|
| Priority: | 3 | Milestone: | 0.3.4 |
| Component: | NRPEListener | Version: | 0.3.1 |
| Severity: | Bugs | Keywords: | |
| Cc: |
Description (last modified by mickem)
csscript, cmd, bat, com, exe, perl are ok with nsclient++
powershell script (ps1) are blocking in nsclient. This is the new
way to program in windows, for example to monitor exchange2007.
When the timeout comes, the connexion is broken, but the powershell script
is already running, and the nsclient sockets are open in this shell (you
can't restart nsclient because the socket is already in use)
With the /test switch, i can't seen any output.
This is my powershell script :
write-host "hello world" exit 0
I have tested to run powershell in theses ways :
powershell -NoProfile -NonInteractive c:/temp/test.ps1 cmd /C powershell -NoProfile -NonInteractive c:/temp/test.ps1
and adding powershell command into a bat file and run it
Bye
Change History (12)
comment:1 Changed 5 years ago by ebollengier@…
comment:2 Changed 5 years ago by mickem
- Description modified (diff)
- Owner changed from MickeM to mickem
- Status changed from new to assigned
comment:3 Changed 5 years ago by mickem
- Description modified (diff)
comment:4 Changed 5 years ago by ebollengier@…
I have changed the execution policy of powershells to RemoteSigned?
Set-ExecutionPolicy RemoteSigned
comment:5 follow-up: ↓ 6 Changed 5 years ago by mickem
and that worked?
MickeM
comment:6 in reply to: ↑ 5 Changed 5 years ago by ebollengier
comment:7 Changed 5 years ago by TobiasRoedel
Hi.
Same Problem here.
Tried very hard to get it working.
1.) Tried to put powershell command in nsc.ini directly. No success.
2.) Tried to put powershell command into a batch file and calling this batch file from nsc.ini. Tried it with and without "call" in the ini and with and without "start" in the batch. Tried also with full path. No success.
3.) Tried to call an vb script calling the powershell script. No success.
Did not address the issue of passing arguments through the proxy scripts, but that shout work in an old fashioned manner.
Next problem is that calling the script via "start" (-> batch) or vb opens a new window so the output is not passed back.
At very last I tried to lower the execution policy to unrestricted with no success.
So any other ideas/suggestions?
kind regards,
Tobias Roedel
comment:8 Changed 5 years ago by mickem
- Milestone changed from 0.4.0 to 0.3.4
- Resolution set to fixed
- Status changed from assigned to closed
Work around to run powershell scripts from NSClient++:
[External Scripts] check_powershell=cmd /c echo scripts\powershell.ps1 | powershell.exe -command -
What this does is run powerhsll with the "-" option which assumes script will be given on std input. I also "send the script" as standard input with the echo command.
It is ugly but works, I honestly dont know what to do powershell seems to be broken in regards to this it does not behave as it should.
I have also fixed (in the next nightly) a bug in my code to make sure it will "timeout properly" if you just "run it".
Michael Medin
send the "command" as standard input to powershell which uses the
comment:9 Changed 5 years ago by ebollengier
Thanks for this workaround, it works great !
comment:10 Changed 5 years ago by anonymous
This last workaround worked for me as well on client 0.3.5.1 (x64) thank you.
comment:11 Changed 4 years ago by anonymous
Slight changes needet for me: (Windows server 2008 with exchange 2007)
cmd /c type scripts/test.ps1 |powershell.exe -psconsolefile "c:\Program Files\Microsoft\Exchange Server\Bin\exshell.psc1" -command -
and here you are, using msexchange console commands like get-mailboxstatisics
comment:12 Changed 3 years ago by DonaldGordon
Slight change needed for me, to make the exit codes come out right:
cmd /c echo scripts/test.ps1 $ARG1$ $ARG2$ ; exit $LastExitCode? | powershell.exe -command -
Without the exit $LastExitCode? bit, all nonzero exit codes from your script will result in a powershell exit code of 1, which nagios interprets as a warning.









powershell -NoProfile?? -NonInteractive?? c:/temp/test.ps1
cmd /C powershell -NoProfile?? -NonInteractive?? c:/temp/test.ps1
add powershell command into a bat file and run it