Skip to main content

Network - PowerShell

Network profile​

Get network profile

Get-NetConnectionProfile

Set network profile

Set-NetConnectionProfile
{ -InterfaceIndex <ID> | -Name <name> }
-NetworkCategory { Private | Public }

Show UDP listening port​

Get-NetUDPEndpoint -LocalAddress 0.0.0.0,::1

View owning process ID

Get-NetUDPEndpoint -LocalAddress 0.0.0.0,::1 | 
select OwningProcess,LocalPort

View owning process name

Get-NetUDPEndpoint -LocalAddress 0.0.0.0,::1 | 
select LocalPort,
@{
L="Process";
E={(Get-Process -Id $_.OwningProcess)
.ProcessName}
}

Show TCP listening port​

Get-NetTCPConnection -State Listen [-LocalPort <port>]

Firewall​

Allow ICMP echo request

New-NetFirewallRule `
-DisplayName "ICMPv4 echo request" `
-Direction Inbound `
-Protocol ICMPv4 `
-IcmpType 8 `
-Action Allow

New-NetFirewallRule `
-DisplayName "ICMPv6 echo request" `
-Direction Inbound `
-Protocol ICMPv6 `
-IcmpType 8 `
-Action Allow

VLAN​

Add external virtual switch

Create VLAN interface​

Add-VMNetworkAdapter -ManagementOS -Name "<name>"
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "<name>" -Access -VlanId <VLAN ID>

Remove VLAN interface​

Remove-VMNetworkAdapter -ManagementOS -Name "<name>"