check_ncpa & powershell

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
melidonis
Posts: 4
Joined: Mon Mar 18, 2019 9:06 am

check_ncpa & powershell

Post by melidonis »

Hi.
I'm trying to run a powershell script with check_ncpa and I want to add a snapin. But when I use this command
"Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010"

I get this error :
"Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2."

Any ideas?

Thank you.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: check_ncpa & powershell

Post by ssax »

That is almost acting like you're trying to run that script on a server that doesn't have Exchange installed on it (so no snap-in available), if you run the powershell script manually on the remote server, does it work?

Edit: Another question, is this 32-bit or 64-bit Exchange? Is this a 32-bit or 64-bit OS?
melidonis
Posts: 4
Joined: Mon Mar 18, 2019 9:06 am

Re: check_ncpa & powershell

Post by melidonis »

Exchange is installed on the server and both are 64bit versions. If I run the script on the server it runs correctly.
melidonis
Posts: 4
Joined: Mon Mar 18, 2019 9:06 am

Re: check_ncpa & powershell

Post by melidonis »

I created a script with a single line

Code: Select all

[IntPtr]::Size
and I called it from nagios. The result I got was "4". That means that ncpa is calling the x86 version of powershell and the 64bit version. How can I change that?

Thank you.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: check_ncpa & powershell

Post by ssax »

Ok, that's likely why then, please try changing your ncpa.cfg .ps1 definition from:

Code: Select all

.ps1 = powershell -ExecutionPolicy Bypass -File $plugin_name $plugin_args
To the 64 bit version:

Code: Select all

.ps1 = %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File $plugin_name $plugin_args
Then restart the ncpa_listener service and see if it works properly now.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: check_ncpa & powershell

Post by ssax »

Or you might be able to rename your powershell plugin to pluginname.ps64 and add the line below as an alternate means of having both:

Code: Select all

.ps64 = %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File $plugin_name $plugin_args
Locked