Skip to content

Instantly share code, notes, and snippets.

@ctigeek
Created April 7, 2015 16:27
Show Gist options
  • Select an option

  • Save ctigeek/a3579e99af234b965f1e to your computer and use it in GitHub Desktop.

Select an option

Save ctigeek/a3579e99af234b965f1e to your computer and use it in GitHub Desktop.
Change server from DHCP to static...
$adapter = Get-NetAdapter -Name "Ethernet"
$ipv4 = $adapter | Get-NetIPAddress -AddressFamily IPv4
## Remove IPv6 Address and disable IPv6 binding....
$ipv6 = $adapter | Get-NetIPAddress -AddressFamily IPv6 -ErrorAction SilentlyContinue
if ($ipv6) {
$ipv6 | Remove-NetIPAddress -Confirm:$false
}
$binding = (Get-NetAdapterBinding | Where-Object { $_.ComponentID -eq "ms_tcpip6" })
if ($binding.Enabled) {
Write-Host "Disabling IPv6 bindings..."
$binding | Disable-NetAdapterBinding
}
$currentDHCPStatus = ($adapter | Get-NetIPInterface).Dhcp
if ($currentDHCPStatus -ne "Disabled") {
#Set IPv4 to static...
$dnsAddresses = (Get-DnsClientServerAddress | Where-Object { $_.AddressFamily -eq 2 -and $_.InterfaceAlias -eq "Ethernet" })[0].ServerAddresses
$address = $ipv4.IPAddress
$prefixLength = $ipv4.PrefixLength
##TODO: get current gateway from dhcp config...
$defaultGateway = "1.2.3.4"
$adapter | Set-NetIPInterface -Dhcp Disabled
$adapter | New-NetIPAddress -IPAddress $address -PrefixLength $prefixLength –DefaultGateway $defaultGateway
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses $dnsAddresses
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment