I am new to PowerShell. An issue I am having is, when I run scripts against hundreds of servers, some of those servers are showing RPC unavailable in the PowerShell command line.
e.g if I run the script:
$list = Get-Content "C:\Users\hostnames.txt" foreach ($computer in $list) { Try { gwmi win32_networkadapterconfiguration -computername $computer -filter "ipenabled = 'true'" | select dnshostname,ipaddress,defaultipgateway,dnsserversearchorder,winsprimaryserver,winssecondaryserver | ft -property * -autosize | out-string -Width 4096 >>dnschgchecks.txt } Catch { "$computer.name failed" >>dnschgchecks.txt } } Some of the hosts report the following in the command line:
gwmi : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) At C:\Users\dnschgchecks.ps1:4 char:1 + gwmi win32_networkadapterconfiguration -computername $computer -filter "ipenable ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
The issue is, I cannot tell which hosts failed to complete the gwmi command out of hundreds of hosts. I don't want to have to check the logs for missing entries to figure out which ones. So, how can I tell which hosts failed? I guess my options are
- Modify the script somehow?
- Use another script to test PowerShell connectivity first, but how?
I am using PowerShell 2 / 4 for the scripts.