Page 1 of 1

Check NCPA , PSSnappin error for Exchange 2013

Posted: Mon Jul 15, 2019 5:11 pm
by Keystone
System : Windows 2012ServerR2 6.3.9600
where the servers are located [In DMZ or not] : Servers are in the DMZ and not domain members.
ncpac version : 2.1.1
Version of Exchange : Exchange 2013

one of my team is attempting to load a Powershell PSSnapin for exchange on these systems so I can interrogate the message queue for monitoring. When using ncpa to load the service monitor Exchange Queue Length, the script fails.

The error is related to loading the Exchange powershell snapin loaded to execute the powershell script that returns queue length. The script get-QueueLength.ps1 runs on the server however fails to load when executed from Nagios


[nagios@monrck-vccn003 ~]$ /usr/local/nagios/libexec/check_ncpa.py -H server -t 'token' -P 5693 -M 'plugins/Nagios_Get-QueueLength.ps1'
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version
4.
At C:\Program Files (x86)\Nagios\NCPA\plugins\Nagios_Get-QueueLength.ps1:8
char:1
+ Add-PSSnapin "Microsoft.Exchange.Management.PowerShell.SnapIn"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Excha...werShell.Sna
pIn:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad
dPSSnapinCommand

We Also Tried the some troubleshooting steps by following a post #53056 and we still face with the below errors


.ps1 = C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\Program Files\Microsoft\Exchange Server\V15\bin\Microsoft.Exchange.PowerShell.Configuration.dll"

Still getting this:

$ /usr/local/nagios/libexec/check_ncpa.py -H server -t 'token' -P 5693 -M 'plugins/Nagios_Get-QueueLength.ps1'
Processing -File '"Microsoft.Exchange.Management.PowerShell.SnapIn"' failed: Illegal characters in path. Specify a valid path for the -File parameter.


Or when I use single quotes around the full snappin name like this 'Microsoft.Exchange.Management.PowerShell.SnapIn':
$ /usr/local/nagios/libexec/check_ncpa.py -H server -t 'token' -P 5693 -M 'plugins/Nagios_Get-QueueLength.ps1'
Processing -File ''Microsoft.Exchange.Management.PowerShell.SnapIn'' failed because the file does not have a '.ps1' extension. Specify a valid Windows PowerShell script file name, and then try again.

Re: Check NCPA , PSSnappin error for Exchange 2013

Posted: Tue Jul 16, 2019 8:51 am
by lmiltchev
It is possible that you need to modify the ncpa.cfg by using the 64-bit powershell. Comment out the "default .ps1" line (or whatever you currently have), e.g.:

Code: Select all

# .ps1 = powershell -ExecutionPolicy Bypass -File $plugin_name $plugin_args
and uncomment the following line:

Code: Select all

.ps1 = c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args
Save, exit, and restart NCPA services on the Windows machine. Try your check again. Did this help?

Re: Check NCPA , PSSnappin error for Exchange 2013

Posted: Tue Jul 16, 2019 4:20 pm
by Keystone
we tried that and we still get issue. Added our ncpa Config screenshot.

We do have this work on other exchange servers, only thing that seems different to this server is that its not a domain members.

we tried bunch of combination

.ps1 = %SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args
.ps1 = %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args

.ps1 = C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args
.ps1 = c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args

The script works fine only when executed locally from powershell in the machine,
The same script when ran form powershell(x86) it fails with the same error

We did restart NCPA listener service every time we tested

Re: Check NCPA , PSSnappin error for Exchange 2013

Posted: Wed Jul 17, 2019 9:42 am
by lmiltchev
The same script when ran form powershell(x86) it fails with the same error
Previously, you showed us a few different errors. Which of these are you seeing now? Can you show us the ncpa_listener.log?

Re: Check NCPA , PSSnappin error for Exchange 2013

Posted: Wed Jul 17, 2019 7:18 pm
by Keystone
Attached is the ncpa_listener log file

Re: Check NCPA , PSSnappin error for Exchange 2013

Posted: Thu Jul 18, 2019 10:26 am
by lmiltchev
I spoke to our developers, and they believe it is possible that you are not using the proper powershell version. You can try using:

Code: Select all

.ps1 = C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args
to see if this is going to fix the issue.

We don't have access to your system, and cannot test this in-house, so it is hard to troubleshoot the issue. According to Microsoft, Add-PSSnapin adds the snap-in only to the current session. Have you tried adding the snap-in to your Windows PowerShell profile?

https://docs.microsoft.com/en-us/powers ... rshell-5.1

Re: Check NCPA , PSSnappin error for Exchange 2013

Posted: Thu Jul 18, 2019 2:58 pm
by Keystone
Thank you, Adding the PSSnappin to $profile.AllUsersAllHosts fixed the issue.

Re: Check NCPA , PSSnappin error for Exchange 2013

Posted: Thu Jul 18, 2019 3:38 pm
by mbellerue
Glad to hear this worked!