Page 1 of 1

NCPA execute PS1 Script with specific Powershell Version

Posted: Mon Sep 04, 2017 4:02 am
by domsch1988
Hallo everyone,

I'm trying to get a Powershell script running to Monitor Veeam Jobs.
The Problem is, that the Veeam SnapIn is not compatible with Powershell Version 4. Nagios defaults to Powershell 4 on the Server though.

Is there any option to make ncpa use a lower Powershell version?

Re: NCPA execute PS1 Script with specific Powershell Version

Posted: Tue Sep 05, 2017 7:30 am
by tacolover101
have you tried including the full path to Powershell 2/3 to your PS executeable? i don't think this is the most viable solution, but it should work.

for example -
if you were just executing check_veeam.ps1 before, try C:\program files\powershell2\powershell.exe C:\check_veeam.ps1 - may need to use quotes to keep the spaces encapsulated.

Re: NCPA execute PS1 Script with specific Powershell Version

Posted: Tue Sep 05, 2017 11:54 am
by mcapra
domsch1988 wrote:Nagios defaults to Powershell 4 on the Server though.
If you're calling the script via NCPA, and you're doing something like -M 'plugins/my_custom_plugin.ps1', then NCPA I believe is going to default to whatever handler Windows has for the .ps1 extension. Be it Powershell 4, MS Paint, or something else entirely (this is how Popen works I think).

Short of setting up proper environment variables and having different Powershell executables associated with different extensions (maybe .ps3 for Powershell 3?), this is probably the easiest solution:
tacolover101 wrote:have you tried including the full path to Powershell 2/3 to your PS executeable?
Essentially, you'd have a wrapper script (a .bat file would be easy) which would be responsible for executing your Powershell script. Then, you'd call that .bat file via NCPA. The .bat file doesn't need to be very complex. It could be as easy as:

Code: Select all

powershell -version 2 .\my_custom_plugin.ps1
Then, I could call that .bat file via NCPA with -M 'plugins/my_wrapper.bat' and it would in turn execute my_custom_plugin.ps1 with whatever environment/executable you like.

Re: NCPA execute PS1 Script with specific Powershell Version

Posted: Tue Sep 05, 2017 2:54 pm
by dwhitfield
Thanks @tacolover101 and @mcapra!

OP, did you have any additional questions or want to add anything?