Page 1 of 1

Powershell Execution Policy Bypass

Posted: Wed Nov 14, 2018 9:54 am
by redskins1234
The current powershell wrapping looks like the following, and requires your execution policy to be set to remote signed.
;Powershell wrapping
ps1=cmd /c echo scripts\\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -
Ideally in our environment, we do not want to open up the execution policy. We've avoided this when running scripts via task scheduler by running them in the following way
powershell.exe -NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File C:\PATH\TO\FILE\script.ps1
Bolded for attention is the switch that lets an admin do a one time bypass of the execution policy. This lets us keep it restricted system wide, while still running automated tasks.

From my own research and testing, Nagios does not support this switch, due to the weird wrapping.

Is there any possibility of further support for this in the future?

Re: Powershell Execution Policy Bypass

Posted: Wed Nov 14, 2018 5:21 pm
by ssax
You must be referring to NSClient++, correct?

What version of NSClient++ are you running? You can find the version next to the program in the Programs and Features control panel item.

While I did not update my wrappings, I have a command defined with exactly this that works as expected:

Code: Select all

[/settings/external scripts/scripts]
check_ohm_temperatures=cmd /c echo scripts\\check_ohm_temperatures.ps1 -warning $ARG1$ -critical $ARG2$; exit($lastexitcode) | powershell.exe -noprofile -executionpolicy bypass -command -
Can you explain by what you mean by "Nagios does not support this switch, due to the weird wrapping." so that we can troubleshoot further?

Re: Powershell Execution Policy Bypass

Posted: Mon Dec 10, 2018 5:10 pm
by redskins1234
Hmm, looks like this does work. On some hosts it was not working so maybe it's an issue of different versions? Either way, thank you.

Re: Powershell Execution Policy Bypass

Posted: Tue Dec 11, 2018 4:51 pm
by ssax
That could be, did you try upgrading the version to see if that fixes it on the ones that aren't working? Are the nsclient.ini configs the same?

Re: Powershell Execution Policy Bypass

Posted: Wed Jan 30, 2019 5:11 pm
by ssax
@AudyIltis, that is correct, thank you for posting that information, future readers will certainly find it useful info.