Created
October 2, 2017 14:13
-
-
Save sapslaj/10804573c5503514d254ee162d8a9469 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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