Created
April 21, 2016 18:26
-
-
Save rikonor/50855c98ae1f6f3c7b79c215b1e922bb to your computer and use it in GitHub Desktop.
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
$desiredPrimary = "127.0.0.1" | |
# Get current DNS Servers | |
$foo = Get-DnsClientServerAddress | where { $_.InterfaceAlias -eq "Ethernet"} | ? {$_.AddressFamily -eq 2 } | |
$dnsServers = $foo.ServerAddresses | |
# Stop if primary is already localhost | |
if ($dnsServers[0].Equals($desiredPrimary)) { | |
echo "Primary DNS Server is already set to 127.0.0.1" | |
exit 0 | |
} | |
# Prepend localhost as Primary DNS Server | |
$newDNSServersList = New-Object 'System.Collections.Generic.List[string]' | |
$newDNSServersList.Add($desiredPrimary) | |
# Add the rest | |
ForEach ($dnsServer in $dnsServers) { | |
$newDNSServersList.Add($dnsServer) | |
} | |
# Set the new DNS Servers list | |
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses $newDNSServersList | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment