adienakhmad revised this gist . Go to revision
1 file changed, 22 insertions
set_static.ps1(file created)
| @@ -0,0 +1,22 @@ | |||
| 1 | + | $IP = "10.10.10.10" | |
| 2 | + | $MaskBits = 24 # This means subnet mask = 255.255.255.0 | |
| 3 | + | $Gateway = "10.10.10.1" | |
| 4 | + | $Dns = "10.10.10.100" | |
| 5 | + | $IPType = "IPv4" | |
| 6 | + | # Retrieve the network adapter that you want to configure | |
| 7 | + | $adapter = Get-NetAdapter | ? {$_.Status -eq "up"} | |
| 8 | + | # Remove any existing IP, gateway from our ipv4 adapter | |
| 9 | + | If (($adapter | Get-NetIPConfiguration).IPv4Address.IPAddress) { | |
| 10 | + | $adapter | Remove-NetIPAddress -AddressFamily $IPType -Confirm:$false | |
| 11 | + | } | |
| 12 | + | If (($adapter | Get-NetIPConfiguration).Ipv4DefaultGateway) { | |
| 13 | + | $adapter | Remove-NetRoute -AddressFamily $IPType -Confirm:$false | |
| 14 | + | } | |
| 15 | + | # Configure the IP address and default gateway | |
| 16 | + | $adapter | New-NetIPAddress ` | |
| 17 | + | -AddressFamily $IPType ` | |
| 18 | + | -IPAddress $IP ` | |
| 19 | + | -PrefixLength $MaskBits ` | |
| 20 | + | -DefaultGateway $Gateway | |
| 21 | + | # Configure the DNS client server IP addresses | |
| 22 | + | $adapter | Set-DnsClientServerAddress -ServerAddresses $DNS | |
Newer
Older