Skip to content

Instantly share code, notes, and snippets.

@sapslaj
Last active August 9, 2017 22:38
Show Gist options
  • Save sapslaj/e41fd7f1eefbfcb9ed9d03e4423f37ca to your computer and use it in GitHub Desktop.
Save sapslaj/e41fd7f1eefbfcb9ed9d03e4423f37ca to your computer and use it in GitHub Desktop.
Quickly change DNS settings
# Automatically elevate to administrator
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
}
Add-Type -AssemblyName System.Windows.Forms
####################
$Interface = "Ethernet 1"
$DnsServers = @(
"8.8.8.8",
"4.2.2.2",
"208.67.222.222"
)
####################
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "Quick DNS Setting"
$Form.TopMost = $true
$Form.Width = 315
$Form.Height = 165
$CurrentServer = (Get-DnsClientServerAddress -InterfaceAlias $Interface -AddressFamily IPv4).ServerAddresses | Select-Object -First 1
$DnsServerSelectionBox = New-Object System.Windows.Forms.ComboBox
$DnsServerSelectionBox.Width = 227
$DnsServerSelectionBox.Height = 20
$DnsServerSelectionBox.location = New-Object system.drawing.point(34,32)
$DnsServerSelectionBox.Text = $CurrentServer
foreach($DnsServer in $DnsServers)
{
$DnsServerSelectionBox.Items.add($DnsServer)
}
$Form.controls.Add($DnsServerSelectionBox)
$ConfirmButton = New-Object System.Windows.Forms.Button
$ConfirmButton.Text = "Confirm"
$ConfirmButton.Width = 80
$ConfirmButton.Height = 30
$ConfirmButton.Add_Click(
{
Set-DnsClientServerAddress -InterfaceAlias $Interface -ServerAddress ($DnsServerSelectionBox.SelectedItem.ToString())
$Form.Close();
})
$ConfirmButton.location = New-Object System.Drawing.Point(34,78)
$Form.controls.Add($ConfirmButton)
$SetDefaultButton = New-Object System.Windows.Forms.Button
$SetDefaultButton.Text = "Obtain Automatically"
$SetDefaultButton.Width = 140
$SetDefaultButton.Height = 30
$SetDefaultButton.Add_Click(
{s
Set-DnsClientServerAddress -InterfaceAlias $Interface -ResetServerAddresses
$Form.Close();
})
$SetDefaultButton.location = New-Object System.Drawing.Point(120,78)
$Form.controls.Add($SetDefaultButton)
[void]$Form.ShowDialog()
$Form.Dispose();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment