Skip to content

Instantly share code, notes, and snippets.

@Cabeda
Created April 7, 2018 18:38
Show Gist options
  • Save Cabeda/cb0906567a81c083a523a9b213a03094 to your computer and use it in GitHub Desktop.
Save Cabeda/cb0906567a81c083a523a9b213a03094 to your computer and use it in GitHub Desktop.
Powershell Script to change the DNS directory
#Functions
function CheckAdminRights() {
# Check if it has admin rights
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
Pause
Break
}
}
function Show-Menu() {
param (
[string]$Title = 'DNS Switcher'
)
Write-Host "================ $Title ================"
Write-Host "Which DNS provider do you prefer? (default = CloudFare)"
Write-Host "1: Press '1' for Google Public DNS."
Write-Host "2: Press '2' for CloudFare"
Write-Host "3: Press '3' for Cisco OpenDNS"
Write-Host "Q: Press 'Q' to quit."
$optionSelected = Read-Host "Select an option:"
return $optionSelected
}
function GetDnsIP ($optionSelected) {
$dnsCloudFare = ("1.1.1.1", "1.0.0.1")
$dnsGoogle = ("8.8.8.8", "8.8.4.4")
$dnsCisco = ("208.67.222.222", "208.67.220.220")
switch ($optionSelected) {
'1' {
$dns = $dnsGoogle
Write-Host 'Switching to Google DNS '
} '2' {
$dns = $dnsCloudFare
Write-Host 'Switching to Cloudfare DNS '
}'3' {
$dns = $dnsCisco
Write-Host 'Switching to Cisco OpenDNS '
} 'q' {
Write-Host 'Exiting the application'
return
}
default {
$dns = $dnsCloudFare
Write-Host 'Switching to Cloudfare DNS '
}
}
return $dns
}
CheckAdminRights
$optionSelected = Show-Menu
$dns = GetDnsIP $optionSelected
$ipConfig = Get-NetIPConfiguration
Write-Host("Switching " + $ipConfig.InterfaceAlias)
Set-DnsClientServerAddress -InterfaceAlias $ipConfig.InterfaceAlias -ServerAddresses $dns
Write-Host "Finished changing the DNS :-) "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment