Get-WmiObject : The RPC server is unavailable. (Ex

2020-02-08 04:51发布

When I run

Get-WmiObject win32_SystemEnclosure -Computer hostname | select serialnumber

it works for both local and remote hosts.

When I do this for a list of hosts using

ForEach ($_ in gc u:\pub\list.txt) {
    Get-WmiObject win32_SystemEnclosure -Computer $_ | select serialnumber | format-table -auto @{Label="Hostname"; Expression={$_}}, @{Label="Service Tag"; Expression={$_.serialnumber}}
}

it returns

Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

标签: powershell
15条回答
姐就是有狂的资本
2楼-- · 2020-02-08 05:46

Check that the "Windows Management Instrumentation (WMI-In)" rule is enabled in the firewall for each remote machine.

Or in an Administrative Command/Powershell prompt run:

netsh advfirewall firewall set rule group="Windows Management Instrumentation (WMI)" new enable=yes
查看更多
甜甜的少女心
3楼-- · 2020-02-08 05:46

I faced the similar issue on new server that I built through automated scripts via vcenter api. Looks like the "Remote Procedure Call (RPC)" service may not be running on the remote machine. you need to wait for the service to come up to use the Get-WmiObject command. Hence I simply put the script into sleep for sometime and it worked.

查看更多
Rolldiameter
4楼-- · 2020-02-08 05:46

I was doing this mistake

ForEach ($server in $servers) {
$OS = Get-WmiObject win32_operatingsystem -ComputerName $server
}

Which, of course, couldn't be passed, because output of the server in a csv file was @{Name=hv1g.contoso.com}

I had to call the property from csv file like this $server.Name

ForEach ($server in $servers) {
$OS = Get-WmiObject win32_operatingsystem -ComputerName $server.Name
}

It fixed my issue.

查看更多
登录 后发表回答