oliviano
10/2/2019 - 12:57 AM

PowerShell Commands (network)

NETWORKING

NetConnection Profile: Private / Public

Get-NetConnectionProfile

Set Network based on Network name to public or private:
Set-NetConnectionProfile -Name "Network" -NetworkCategory Public
Set-NetConnectionProfile -Name "Network" -NetworkCategory Private

Net InterfaceMetrictric ( lower is higher priority )

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

Net Route ( Checking for gateway settings )

Get-NetRoute -InterfaceIndex 12

Change Policy

Allow User Script execution:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUse

WIP SCRIPTS: Set Network for Interface

# 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.