Page 1 of 1
powershell script remote server
Posted: Tue Mar 16, 2021 6:46 am
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
Re: powershell script remote server
Posted: Wed Mar 17, 2021 9:35 am
by vtrac
Hi,
May I see your nrpe command, please?
Also, please upload your script here as well.
Regards,
Vinh
Re: powershell script remote server
Posted: Thu Mar 18, 2021 2:51 am
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
Re: powershell script remote server
Posted: Thu Mar 18, 2021 10:53 am
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
)
Re: powershell script remote server
Posted: Thu Mar 18, 2021 11:24 am
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

Re: powershell script remote server
Posted: Thu Mar 18, 2021 11:29 am
by vtrac
Yes, thank you @optionstechnology ....
