Version 9 (modified by spirillen, 2 weeks ago) ( diff )



Windows PowerShell DNS server switcher

This script is made to pick up My Privacy DNS server IP-addresses and then apply them as your default DNS Servers for enhanced Privacy If you’re using PS 3.0 or greater (on your local computer), then use the Using scope modifier.

Save this script as "SecureDNSSwitcher.ps1"

$NIC_PrimaryDNS = ""
$NIC_SecondaryDNS = ""
Invoke-command -ComputerName $Server -cred $cred -ScriptBlock {Set-DnsClientServerAddress -InterfaceAlias corp -ServerAddresses("$Using:NIC_PrimaryDNS","$Using:NIC_SecondaryDNS")}

If you’re using 2.0, then you’ll have to use parameters to pass in your local variables.

$ns0ip1 = [System.Net.Dns]::GetHostAddresses("")[0] | foreach {echo $_.IPAddressToString }
$ns0ip2 = [System.Net.Dns]::GetHostAddresses("")[1] | foreach {echo $_.IPAddressToString }
$ns1ip1 = [System.Net.Dns]::GetHostAddresses("")[0] | foreach {echo $_.IPAddressToString }
$ns1ip2 = [System.Net.Dns]::GetHostAddresses("")[1] | foreach {echo $_.IPAddressToString }

$NICs = Get-NetAdapter | where status -eq 'Up' | select -exp Name
Foreach($NIC in $NICs) {

$DNSServers = "$ns0ip1","$ns0ip2","$ns1ip1","$ns1ip2"
Set-DnsClientServerAddress -InterfaceAlias $NIC -ServerAddresses ($DNSServers)

To run the script you have to unblock the file with Unblock-File -Path "SecureDNSSwitcher.ps1" and the run it by typing .\SecureDNSSwitcher.ps1 within your PowerShell

Dns related articles
DnsDist, DnsFirewall, DnsHosts, DnsMasq, DnsScripts, DnsSetup

Attachments (1)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.