Created
October 21, 2020 22:41
-
-
Save davejlong/43e888f41cd0c4a7588aef20de2ff93c to your computer and use it in GitHub Desktop.
Check and set DNS for primary interface to OpenDNS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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