Get-NetConnectionProfile
Set Network based on Network name to public or private:
Set-NetConnectionProfile -Name "Network" -NetworkCategory Public
Set-NetConnectionProfile -Name "Network" -NetworkCategory Private
Get List of interface with Index:
Get-NetIPInterface
Use Interface Index to change Metric:
Set-NetIPInterface -InterfaceIndex 21 -InterfaceMetric 10
Reset to default:
Set-NetIPInterface -InterfaceIndex 21 -AutomaticMetric enabled
Get-NetRoute -InterfaceIndex 12
Allow User Script execution:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUse
# Variables
$InterfaceIndex = 39
$IPAddress = "10.10.1.140"
$Gateway = "10.10.1.1"
$PrefixLength = 24 # This corresponds to subnet mask 255.255.255.0
# Remove existing IP address
Get-NetIPAddress -InterfaceIndex $InterfaceIndex | Remove-NetIPAddress -Confirm:$false
# Assign new IP address
New-NetIPAddress -InterfaceIndex $InterfaceIndex -IPAddress $IPAddress -PrefixLength $PrefixLength -DefaultGateway $Gateway
# Removing the Default Gateway ( IP v4 Only )
# Get-NetRoute -InterfaceIndex $InterfaceIndex | Where-Object { $_.DestinationPrefix -eq '0.0.0.0/0' } | Remove-NetRoute -Confirm:$false
Get-NetRoute -InterfaceIndex $InterfaceIndex -AddressFamily IPv4 | Where-Object { $_.DestinationPrefix -eq '0.0.0.0/0' } | Remove-NetRoute -Confirm:$false
Prototype for code block to manage machine deployment.