Nagios Issue - gwmi : The RPC server is unavailable

0

I'm struggling with a problem regarding the RPC server being unavailable specifically for a Nagios script written in PowerShell.

When the script is run locally, it runs perfectly and as expected. When it is called via the NRPE agent and run by the nscp service, it fails with this error:

gwmi : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Program Files\NSClient++\scripts\check_win_uptime.ps1:30 char:8
+ $wmi = gwmi Win32_OperatingSystem -computer $ServerName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands
.GetWmiObjectCommand

The guts of the script (or relevant parts) are this:

$wmi = gwmi Win32_OperatingSystem -computer $ServerName
$LBTime = $wmi.ConvertToDateTime($wmi.Lastbootuptime)
[TimeSpan]$uptime = New-TimeSpan $LBTime $(get-date)

No firewall is running and for testing purposes, all ports are open to the server.

Any suggestions are greatly appreciated.

Mike

powershell
windows-server-2008
wmi
nagios
asked on Stack Overflow May 30, 2013 by Mike J

2 Answers

0

RPC Server Unavailable is almost always not having enabled the right settings in Windows firewall. See this very old topic I got written for MSDN while on the WMI team to document the issue.

Connecting thru Windows Firewall

answered on Stack Overflow May 30, 2013 by Start-Automating
0

Get-wmiobject -computer is very finicky. This works for me:

$c = get-credential
Get-WmiObject -Class win32_computersystem -ComputerName comp001 -Credential $c 

But other forms give the "Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)" error:

Get-WmiObject win32_computersystem -ComputerName comp001 -Credential $c 
Get-WmiObject -Class win32_computersystem -ComputerName comp001 # running as same domain user as creds

So it looks like -Class and -Credential are mandatory.

Sometimes only something like this works:

Get-WmiObject -ComputerName comp001 -Credential "dom\js" -Query "SELECT * FROM Win32_ComputerSystem"
answered on Stack Overflow Sep 30, 2019 by js2010

User contributions licensed under CC BY-SA 3.0