Skip to content

Instantly share code, notes, and snippets.

@davejlong
Created October 21, 2020 22:41
Show Gist options
  • Save davejlong/43e888f41cd0c4a7588aef20de2ff93c to your computer and use it in GitHub Desktop.
Save davejlong/43e888f41cd0c4a7588aef20de2ff93c to your computer and use it in GitHub Desktop.
Check and set DNS for primary interface to OpenDNS
$DnsServers = @("208.67.220.220", "208.67.222.222")
$Route = Get-NetRoute -DestinationPrefix 0.0.0.0/0
$IfIndex = $Route.ifIndex
$DnsAddresses = Get-DnsClientServerAddress -InterfaceIndex $IfIndex -AddressFamily IPv4
$DnsAddresses.ServerAddresses | ForEach-Object {
if ($_ -notin $DnsServers) {
Write-Host "Fixing DNS Servers"
Set-DnsClientServerAddress -InterfaceIndex $IfIndex -ServerAddresses $DnsServers
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment