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

前端 未结 16 2041
失恋的感觉
失恋的感觉 2020-12-08 13:32

When I run

Get-WmiObject win32_SystemEnclosure -Computer hostname | select serialnumber

it works for both local and remote hosts.

W

16条回答
  •  广开言路
    2020-12-08 14:12

    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}}
    }
    

提交回复
热议问题