NCPA execute PS1 Script with specific Powershell Version

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
domsch1988
Posts: 32
Joined: Tue Aug 15, 2017 1:20 am

NCPA execute PS1 Script with specific Powershell Version

Post 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?
User avatar
tacolover101
Posts: 432
Joined: Mon Apr 10, 2017 11:55 am

Re: NCPA execute PS1 Script with specific Powershell Version

Post 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.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: NCPA execute PS1 Script with specific Powershell Version

Post 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.
Former Nagios employee
https://www.mcapra.com/
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: NCPA execute PS1 Script with specific Powershell Version

Post by dwhitfield »

Thanks @tacolover101 and @mcapra!

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