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:22

I just came to the exact same issue and found the answer here: http://powershellcommunity.org/Forums/tabid/54/aft/7537/Default.aspx

I had space characters at the end of each line the input file. If your file does too, just remove them and your script should work.

查看更多
我命由我不由天
3楼-- · 2020-02-08 05:23

It might be due to various issues.I cant say which one is there in your case.

Below given reasons may be there:

  • DCOM is not enabled in host PC or target PC or on both.
  • Your Firewall or even your antivirus is preventing the access.
  • Any WMI related service is disabled.

Some WMI related services are as given:

  • Remote Access Auto Connection Manager
  • Remote Access Connection Manager
  • Remote Procedure Call (RPC)
  • Remote Procedure Call (RPC) Locator
  • Remote Registry

For DCOM setting refer:

  • Key: HKLM\Software\Microsoft\OLE, Value: EnableDCOM

The value should be set to 'Y' .

查看更多
相关推荐>>
4楼-- · 2020-02-08 05:24

Your code probably isn't using a correct machine name, you should double check that.

Your error is:

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

This is the result you get when a machine is not reachable. So the firewall suggestions are reasonable, but in this case probably not correct because you say this works:

Get-WmiObject win32_SystemEnclosure -Computer hostname

So in your case it seems when this line is executed:

Get-WmiObject win32_SystemEnclosure -Computer $_

$_ doesn't contain a proper computer name. You could check type and contents of $_. Probably there is a problem with the file contents. If the file looks right, then maybe the lines are not properly terminated. Maybe take a closer look using Write-Host:

ForEach ($_ in gc u:\pub\list.txt) {
    Write-Host "Get-WmiObject win32_SystemEnclosure -Computer '$_'"
    Get-WmiObject win32_SystemEnclosure -Computer $_ | select serialnumber | format-table -auto @{Label="Hostname"; Expression={$_}}, @{Label="Service Tag"; Expression={$_.serialnumber}}
}
查看更多
我只想做你的唯一
5楼-- · 2020-02-08 05:24

I was having the same issue using foreach. I saved the list to $servers and used this which worked:

ForEach ($_ in $Servers) { Write-Host "Host $($_)" | Get-WmiObject win32_SystemEnclosure -Computer $_ | format-table -auto @{Label="Service Tag"; Expression={$_.serialnumber}}
}
查看更多
Deceive 欺骗
6楼-- · 2020-02-08 05:27

Turning the firewall off resolved it for me.

查看更多
干净又极端
7楼-- · 2020-02-08 05:28

I was having the same problem but only with a few machines. I found that using Invoke-Command to run the same command on the remote server worked.

So instead of:

Get-WmiObject win32_SystemEnclosure -ComputerName $hostname -Authentication Negotiate

Use this:

Invoke-Command -ComputerName $hostname -Authentication Negotiate -ScriptBlock {Get-WmiObject win32_SystemEnclosure}
查看更多
登录 后发表回答