windows-toolbox/Installs/PowerShell/SetStaticIPAddress.ps1

35 lines
1.1 KiB
PowerShell
Raw Permalink Normal View History

2024-07-16 01:25:46 -04:00
# Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
# $IP=$args[0]
# Write-Host "Passed Arguments: $Argument"
# $IP = Read-Host -Prompt 'Input IP Address 206.210.XX.XX'
$IP=$args[0]
Write-Host "Passed Arguments: $Argument"
# $IP = "206.210." + $Address
$MaskBits = 20
$Gateway = "206.210.40.1"
$Dns1 = "206.210.36.54"
$Dns2 = "206.210.41.1"
$IPType = "IPv4"
# Retrieve the network adapter that you want to configure
$adapter = Get-NetAdapter | ? {$_.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 $DNS1, $DNS2