powershell script remote server

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
[email protected]
Posts: 6
Joined: Wed Sep 28, 2016 5:10 am

powershell script remote server

Post by [email protected] »

Hi all,

i try to use a powershell script in nagios with this command:

$size = (Get-Item REMOTESERVER\d$\AppData\Exchange\TransportRoles\data\Queue\mail.que).Length

write-host $size

in powershell it works perfectly but when i try to run the script with nrpe on nagios it always exit with 0 because $size is null

any suggestions?

thanks
User avatar
vtrac
Posts: 903
Joined: Tue Oct 27, 2020 1:35 pm

Re: powershell script remote server

Post by vtrac »

Hi,
May I see your nrpe command, please?

Also, please upload your script here as well.


Regards,
Vinh
[email protected]
Posts: 6
Joined: Wed Sep 28, 2016 5:10 am

Re: powershell script remote server

Post by [email protected] »

the script is:

$size = [math]::round((Get-Item \\server\d$\AppData\Exchange\TransportRoles\data\Queue\mail.que).Length /1GB)
$size = (Get-Item \\server\d$\AppData\Exchange\TransportRoles\data\Queue\mail.que).Length

write-host $size


the command is:

cmd /c echo scripts\check_exchange_mail_queue.ps1 $ARG1$ ; exit($lastexitcode) | powershell.exe -ExecutionPolicy Bypass -command - 2> $null


thanks
optionstechnology
Posts: 234
Joined: Thu Nov 17, 2016 11:26 am

Re: powershell script remote server

Post by optionstechnology »

Any time I see this problem its because nrpe/nagios runs as a local service account and doesn't have access to UNC paths

If your running against a local server try it with the local paths and see if that works


(note I run this exact same check I think using the PS snapin:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;
Get-Queue | Select-Object Identity,MessageCount

Might be a better fit as it can execute locally

)
[email protected]
Posts: 6
Joined: Wed Sep 28, 2016 5:10 am

Re: powershell script remote server

Post by [email protected] »

on local server it works.

probably you're right doesn't have access to UNC paths

in this case I will run on server locally

thanks for suggestions :)
User avatar
vtrac
Posts: 903
Joined: Tue Oct 27, 2020 1:35 pm

Re: powershell script remote server

Post by vtrac »

Yes, thank you @optionstechnology .... :-)
Locked