Created
October 6, 2015 21:42
-
-
Save ducke/f6e42399930b15ddf2a7 to your computer and use it in GitHub Desktop.
This file contains 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
$IP = '192.168.138.10' | |
$MaskBits = 24 # This means subnet mask = 255.255.255.0 | |
$Gateway = '192.168.138.2' | |
$Dns = '192.168.138.2' | |
$IPType = 'IPv4' | |
# Retrieve the network adapter that you want to configure | |
$adapter = Get-NetAdapter | Where-Object {$_.Status -eq 'up'} | |
# Remove any existing IP, gateway from our ipv4 adapter | |
If (($adapter | Get-NetIPConfiguration).IPv4Address.IPAddress) { | |
$adapter | Remove-NetIPAddress -AddressFamily $IPType -Confirm:$false | |
} | |
If (($adapter | Get-NetIPConfiguration).Ipv4DefaultGateway) { | |
$adapter | Remove-NetRoute -AddressFamily $IPType -Confirm:$false | |
} | |
# Configure the IP address and default gateway | |
$adapter | New-NetIPAddress ` | |
-AddressFamily $IPType ` | |
-IPAddress $IP ` | |
-PrefixLength $MaskBits ` | |
-DefaultGateway $Gateway | |
# Configure the DNS client server IP addresses | |
$adapter | Set-DnsClientServerAddress -ServerAddresses $DNS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment