Hi,
I downloaded Nagios Core and setup a server (on ubuntu 14.04) and did monitor Windows machines (Win 8.1 and 2008 R2). I am facing an issue in calling powershell script from server to client. Installed NSClient on the windows machines and added all servers details in the server windows.cfg file, also added command definitions in the commands.cfg file.
While executing powershell scripts from server, I am getting below response :
The command (ps1) returned an invalid return code: -196608
NSCLIENT external scripts section-
[/settings/external scripts/scripts]
ps1 = cmd /c echo scripts\\test1 %ARGS%; exit($lastexitcode) | powershell.exe -ExecutionPolicy Bypass -File -command -
I checked configuration, both server and client side, did not find any issues with configuration. If I remove script from the script location(on client), I am getting response as Unknown command, which is correct. I checked port 5666 as well and it is listening commands from server.
Could you please help me to figure out why it is happening and what would be the resolution for this problem.
Regards,
Arvind
The command (ps1) returned an invalid return code: -196608
Re: The command (ps1) returned an invalid return code: -1966
Can you try to run the command from the commandline on the ubuntu server?
Rob Hassing


Re: The command (ps1) returned an invalid return code: -1966
Hey rhassing, I ran these command command line from server only(using 'check_nrpe' within 'libexec' folder). I also tried to run it from NSCP client as well on client machine, getting the same result.
But if I ran the powershell script command line, they are working fine.
Within NSCP, I can see connections from server and command execution as well, same result, return code -196608.
But if I ran the powershell script command line, they are working fine.
Within NSCP, I can see connections from server and command execution as well, same result, return code -196608.
Re: The command (ps1) returned an invalid return code: -1966
Hi Rob,
I figured it out, I removed '-ExecutionPolicy ByPass -File' within external script section.
ps1 = cmd /c echo scripts\\test1 %ARGS%; exit($lastexitcode) | powershell.exe -ExecutionPolicy Bypass -File -command -
I was bypassing the execution policy instead of setting it to 'RemoteSigned' but it didn't work.
Set ExecutionPolicy as 'RemoteSigned' and re-ran the scripts from server and nscp test, working fine.
Regards,
Arvind
I figured it out, I removed '-ExecutionPolicy ByPass -File' within external script section.
ps1 = cmd /c echo scripts\\test1 %ARGS%; exit($lastexitcode) | powershell.exe -ExecutionPolicy Bypass -File -command -
I was bypassing the execution policy instead of setting it to 'RemoteSigned' but it didn't work.
Set ExecutionPolicy as 'RemoteSigned' and re-ran the scripts from server and nscp test, working fine.
Regards,
Arvind
Re: The command (ps1) returned an invalid return code: -1966
Arvind, thanks for posting the solution, hopefully that will be helpful for others down the line and also thanks rhassing. I'll go ahead and lock this thread now.
Be sure to check out the Knowledgebase for helpful articles and solutions!