'RPC Server is unavailable' error but script still appears to work

时间:2019-03-19 15:10:07

标签: powershell

$computer = get-content C:\test\DNS_Server_Name.csv
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE”}
  Foreach($NIC in $NICs) {

$DNSServers = “198.102.234.125",”198.102.234.126"
 $NIC.SetDNSServerSearchOrder($DNSServers)
 $NIC.SetDynamicDNSRegistration(“TRUE”)
}

Getting error "RPC Server is unavailable". However, the script still inputs the DNS server as needed. I ran this with only one server name in the csv file. Any idea why I'm getting this error even though it still seems to work?

1 个答案:

答案 0 :(得分:1)

您的脚本仍在运行,因为Get-WMIObject cmdlet没有终止,请在understand Non-Terminating Errors in PowerShell上查看本文

如果要在Get-WMIObject生成错误时停止脚本,只需添加–ErrorAction Stop

$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer –ErrorAction Stop | where {$_.IPEnabled -eq “TRUE”}

如果您想获取有关错误“ RPC服务器不可用”本身的更多信息,则可能需要检查是否在防火墙中为每台远程计算机启用了“ Windows Management Instrumentation(WMI-In)”规则,如this answer