18303 shaares
1707 private links
1707 private links
Static
$IP = "192.168.1.101"
$Mask = 24
$Gateway = "192.168.1.1"
$DNS1 = "192.168.1.2"
$DNS2 = "80.67.169.12"
$IPType = "IPv4"
$adapter = Get-NetAdapter | ? {$_.Status -eq "up"}
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
}
$adapter | New-NetIPAddress -AddressFamily $IPType -IPAddress $IP -PrefixLength $Mask -DefaultGateway $Gateway
$adapter | Set-DnsClientServerAddress -ServerAddresses ("$DNS1","$DNS2")
DHCP
$IPType = "IPv4"
$adapter = Get-NetAdapter | ? {$_.Status -eq "up"}
$interface = $adapter | Get-NetIPInterface -AddressFamily $IPType
If ($interface.Dhcp -eq "Disabled") {
If (($interface | Get-NetIPConfiguration).Ipv4DefaultGateway) {
$interface | Remove-NetRoute -Confirm:$false
}
$interface | Set-NetIPInterface -DHCP Enabled
$interface | Set-DnsClientServerAddress -ResetServerAddresses
}