Skip to content

Instantly share code, notes, and snippets.

@sapslaj
Created October 2, 2017 14:13
Show Gist options
  • Save sapslaj/10804573c5503514d254ee162d8a9469 to your computer and use it in GitHub Desktop.
Save sapslaj/10804573c5503514d254ee162d8a9469 to your computer and use it in GitHub Desktop.
$IPType = "IPv4"
$adapter = Get-NetAdapter | ? {$_.Status -eq "up"}
$interface = $adapter | Get-NetIPInterface -AddressFamily $IPType
If ($interface.Dhcp -eq "Disabled") {
# Remove existing gateway
If (($interface | Get-NetIPConfiguration).Ipv4DefaultGateway) {
$interface | Remove-NetRoute -Confirm:$false
}
# Enable DHCP
$interface | Set-NetIPInterface -DHCP Enabled
# Configure the DNS Servers automatically
$interface | Set-DnsClientServerAddress -ResetServerAddresses
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment