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

4

3 回答 3

0

RPC Server Unavailable 几乎总是没有在 Windows 防火墙中启用正确的设置。请参阅我在 WMI 团队中为 MSDN 编写的这个非常古老的主题,以记录该问题。

通过 Windows 防火墙连接

于 2013-05-30T18:59:51.793 回答
0

Get-wmiobject -computer 非常挑剔。这对我有用:

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

但其他形式给出“Get-WmiObject:RPC 服务器不可用。(HRESULT 异常:0x800706BA)”错误:

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

所以看起来 -Class 和 -Credential 是强制性的。

有时只有这样的工作:

Get-WmiObject -ComputerName comp001 -Credential "dom\js" -Query "SELECT * FROM Win32_ComputerSystem"
于 2019-09-30T19:05:03.437 回答
0

我也遇到过类似的问题,但通过 CMD 使用任务列表查看远程进程。答案与烟花配置有关。将其转换为 PowerShell 命令,它将解决您的问题。

netsh advfirework firework set rule group="windows management instrumentation (wmi)" new enable=yes

于 2020-05-09T11:52:32.957 回答