0
$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?

WeeWoo
  • 27
  • 5

1 Answers1

1

Your script still runs because the Get-WMIObject cmdlet is not terminating, check this article to understand Non-Terminating Errors in PowerShell

If you want to stop the script when Get-WMIObject generates an error, just add –ErrorAction Stop

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

If you want further informations about the error "RPC Server is unavailable" itself, you may want to check that the "Windows Management Instrumentation (WMI-In)" rule is enabled in the firewall for each remote machine, as described in this answer.

Fourat
  • 2,366
  • 4
  • 38
  • 53