Skip to content

Instantly share code, notes, and snippets.

@NeraSnow
Created October 25, 2018 03:59
Show Gist options
  • Save NeraSnow/e13c6eb91cd1fb0945eb8f7a5c7f6b7d to your computer and use it in GitHub Desktop.
Save NeraSnow/e13c6eb91cd1fb0945eb8f7a5c7f6b7d to your computer and use it in GitHub Desktop.
Change DNS settings
<#
Credit: https://stackoverflow.com/questions/7690994/powershell-running-a-command-as-administrator
#>
# Runs as admin
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
$dns1 = "218.85.157.99" #China Telecom DNS in Fuzhou, Fujian
$dns2 = "218.85.152.99" #China Telecom DNS in Xiamen, Fujian
netsh interface ip delete dnsservers name="以太网 3" all
netsh interface ip add dnsservers name="以太网 3" address=$dns1
netsh interface ip add dnsservers name="以太网 3" address=$dns2
Set-DnsClientGlobalSetting -SuffixSearchList @()
Read-Host "Press any key to exit..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment