SkillPilotAI

PowerShell Hyper-V networking cmdlets (2/3)

Part 2 of the Hyper-V networking cmdlets: creating and listing virtual switches, VLANs on VM adapters, switch extensions and the big family of Remove-* cmdlets. These are the commands you use to build, inspect and clean up VM networks on a Hyper-V host.

261.1 Why is it used?

  • New-VMSwitch / Get-VMSwitch / Remove-VMSwitch create, list and delete the virtual switch that VMs plug into.
  • Get-VMNetworkAdapterVlan verifies which VLAN (and mode) every VM adapter is in.
  • Switch extension cmdlets show what is installed on the extensible switch and what each feature is configured to.
  • Remove-* cmdlets clean up adapters, ACLs, team members and routing domain mappings precisely.

261.2 Where it runs

  • The Hyper-V module comes with the Hyper-V feature on Windows 10/11 and Windows Server.
  • New-* and Remove-* cmdlets need an Administrator PowerShell.
  • Almost all cmdlets accept -ComputerName and -Credential to manage a remote host.
  • On the office PC in the video the module was not installed (count 0), so switch commands show the docs syntax and the lab runs on Linux.
PowerShell
Get-Command -Module Hyper-V -ErrorAction SilentlyContinue | Measure-Object
Output
PS C:\> Get-Command -Module Hyper-V -ErrorAction SilentlyContinue | Measure-Object Count    : 0

261.3 Get-VMSwitch, New-VMSwitch, Remove-VMSwitch

  • -SwitchType accepts only Internal or Private.
  • An External switch is made by giving -NetAdapterName (or -NetAdapterInterfaceDescription); the type becomes External automatically.
  • -AllowManagementOS $true lets the host also use that physical NIC; -EnableEmbeddedTeaming $true turns on SET teaming.
  • -MinimumBandwidthMode Weight|Absolute|None sets the QoS mode of the switch.
  • Get-VMSwitch with no parameters lists all switches on the local host; Remove-VMSwitch -Force skips the confirmation.
PowerShell
New-VMSwitch -Name LabSw -SwitchType InternalNew-VMSwitch "QoS Switch" -NetAdapterName "Wired Ethernet Connection 3" -MinimumBandwidthMode WeightGet-VMSwitch -SwitchType ExternalRemove-VMSwitch "QoS Switch" -Force
Switch typeWho can talkHow to create
ExternalVMs, host and the physical network-NetAdapterName "Ethernet"
InternalVMs and the host only-SwitchType Internal
PrivateVMs only (not even the host)-SwitchType Private

261.4 VLAN, Rename and Remove of a VM adapter

VLANs on one Hyper-V switch
  1. 1.VM1 (VLAN 10, Access) sends a ping

  2. 2.vSwitch LabSw receives it on a VLAN 10 port

  3. 3.Switch forwards only to VLAN 10 ports -> VM2 replies

  4. 4.VM3 is on VLAN 20, so the frame never reaches it

  5. 5.Get-VMNetworkAdapterVlan shows these per-adapter settings

Same switch, separate broadcast domains

  • Get-VMNetworkAdapterVlan with no parameters returns VLAN settings of every adapter of every VM; -ManagementOS is for the host's own vNICs.
  • Rename-VMNetworkAdapter with -Name renames only that adapter (Private -> CoreNet).
  • Without -Name, ALL adapters of that VM get the new name.
  • Remove-VMNetworkAdapter removes an adapter from a VM; for a host vNIC use -ManagementOS -SwitchName.
PowerShell
Get-VMNetworkAdapterVlanGet-VMNetworkAdapterVlan -VMName Web01Rename-VMNetworkAdapter -VMName Kirkland -Name Private -NewName CoreNetRename-VMNetworkAdapter -VMName Redmond -NewName CoreNetRemove-VMNetworkAdapter -VMName Redmond -VMNetworkAdapterName Redmond_NIC1

261.5 Switch extensions

Extensible switch packet path
  1. 1.VM1 sends a packet into the Hyper-V extensible switch

  2. 2.Capture extension: takes a copy and monitors

  3. 3.Filter extension: checks rules, allow or drop

  4. 4.Forwarding extension: decides the destination port

  5. 5.Packet reaches VM2 (unless a filter dropped it)

  • Get-VMSystemSwitchExtension: which extensions are installed on the host.
  • Get-VMSwitchExtension: extensions on one switch and whether each is enabled; these objects carry no features.
  • Get-VMSystemSwitchExtensionPortFeature / SwitchFeature: supported port-level / switch-level features and their default values.
  • Feature cmdlets return configuration; Data cmdlets return runtime status and statistics.
  • -ExternalPort targets the port of the physical NIC.
PowerShell
Get-VMSystemSwitchExtensionGet-VMSwitch InternalSwitch | Get-VMSwitchExtensionGet-VMSystemSwitchExtensionPortFeatureGet-VMSystemSwitchExtensionSwitchFeatureGet-VMSwitchExtensionPortFeature -VMName VM2 -FeatureName "Ethernet Switch Port Security Settings"Get-VMSwitchExtensionPortData VM1 -FeatureId eb29f0f2-f5dc-45c6-81bb-3cd9f219bbbbGet-VMSwitchExtensionSwitchFeature -SwitchName MySwitchGet-VMSwitchExtensionSwitchData External -FeatureId 1c37e01c-0cd6-496f-9076-90c131033dc2
Cmdlet familyLevelReturns
Get-VMSystemSwitchExtension*HostInstalled extensions / supported features + defaults
Get-VMSwitchExtensionOne switchExtensions, enabled or disabled
Get-VMSwitchExtensionPortFeature / SwitchFeaturePort / switchConfiguration
Get-VMSwitchExtensionPortData / SwitchDataPort / switchRuntime status and statistics
  • Remove-VMSwitchExtensionPortFeature / SwitchFeature remove a feature that is already configured; get it into a variable first.
  • -Passthru returns the removed object.
PowerShell
$feature = Get-VMSwitchExtensionPortFeature -VMName VM2 -FeatureId 776e0ba7-94a1-41c8-8f28-951f524251b5Remove-VMSwitchExtensionPortFeature VM2 -VMSwitchExtensionFeature $feature$feature = Get-VMSwitchExtensionSwitchFeature -SwitchName External -FeatureId 3eb2b8e8-4abf-4dbf-9071-16dd47481fbeRemove-VMSwitchExtensionSwitchFeature External $feature

261.6 Remove ACLs, team members and routing domains

  • Remove-VMNetworkAdapterAcl: -Action (Allow|Deny|Meter) and -Direction (Inbound|Outbound|Both) are required.
  • Pipe Get-VMNetworkAdapterAcl into Remove-VMNetworkAdapterAcl to remove all ACLs at once.
  • Extended ACL entries have a unique -Weight, so -Weight + -Direction removes exactly one entry (no Both here).
  • Get-VMSwitchTeam shows a switch team and its member NICs; Remove-VMSwitchTeamMember takes NICs out of it.
  • Remove-VMNetworkAdapterRoutingDomainMapping removes a tenant routing domain from a multitenant gateway VM's adapter.
  • Remove-VMNetworkAdapterTeamMapping: the docs page has no description or example, only syntax.
PowerShell
Remove-VMNetworkAdapterAcl -VMName Redmond -RemoteIPAddress 0.0.0.0/0 -Direction Both -Action AllowRemove-VMNetworkAdapterAcl -VMName Redmond -RemoteMacAddress 03-0f-01-0e-aa-b2 -Direction Both -Action DenyGet-VMNetworkAdapterAcl -VMName Redmond | Remove-VMNetworkAdapterAclRemove-VMNetworkAdapterExtendedAcl -VMName "TSQA01" -Direction InBound -Weight 50Get-VMSwitchTeam -Name "SwitchTeam07"$VMSwitch = Get-VMSwitch -Name "Switch03"Remove-VMSwitchTeamMember -VMSwitch $VMSwitch -NetAdapterName "Adapter01","Adapter04"Remove-VMNetworkAdapterRoutingDomainMapping -VMName "Gateway01" -VMNetworkAdapterName "Internal NIC" -RoutingDomainID "{5a07361e-6a54-49fc-9210-bfbf14a5c56f}"

261.7 Lab: the same idea on a Linux bridge

  • Bridge vswitch0 in the n261-host container plays New-VMSwitch; vm1/vm2/vm3 are network namespaces joined by veth pairs.
  • vm1 = 192.168.61.11, vm2 = .12, vm3 = .13 (/24).
  • vlan_filtering 1 + pvid untagged on each port = access ports; bridge vlan show = Get-VMNetworkAdapterVlan.
  • VLAN filtering is part of the bridge module itself; the 8021q module was not needed (module list identical).
Terminal
ip link add vswitch0 type bridgeip link set vswitch0 upip link add vm1-p type veth peer name eth0 netns 39   # pid of vm1ip link set vm1-p master vswitch0ip link set vm1-p up# vm1: ip addr add 192.168.61.11/24 dev eth0ip -d link show vswitch0bridge link
Output
[host]$ bridge link4: vm1-p@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master vswitch0 state forwarding priority 32 cost 25: vm2-p@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master vswitch0 state forwarding priority 32 cost 26: vm3-p@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master vswitch0 state forwarding priority 32 cost 2
Terminal
ip link set vswitch0 type bridge vlan_filtering 1bridge vlan add dev vm1-p vid 10 pvid untaggedbridge vlan del dev vm1-p vid 1bridge vlan add dev vm2-p vid 10 pvid untaggedbridge vlan del dev vm2-p vid 1bridge vlan add dev vm3-p vid 20 pvid untaggedbridge vlan del dev vm3-p vid 1bridge vlan show# vm1: ping -c 2 -W 1 192.168.61.12# vm1: ping -c 2 -W 1 192.168.61.13
Output
[vm1]$ ping -c 2 -W 1 192.168.61.1264 bytes from 192.168.61.12: icmp_seq=1 ttl=64 time=13.7 ms64 bytes from 192.168.61.12: icmp_seq=2 ttl=64 time=0.088 ms2 packets transmitted, 2 received, 0% packet loss, time 1002ms[vm1]$ ping -c 2 -W 1 192.168.61.132 packets transmitted, 0 received, 100% packet loss, time 1018ms
  • Rename idea: inside vm2 set eth0 down, rename to corenet, set up; IP 192.168.61.12 stays and ping works again.
  • Remove adapter idea: ip link del vm3-p; Remove switch idea: ip link del vswitch0.
Terminal
ip link set eth0 downip link set eth0 name corenetip link set corenet upip link del vm3-pip link del vswitch0ip link show vswitch0
Output
[host]$ ip link del vswitch0(exit 0)[host]$ ip link show vswitch0Device "vswitch0" does not exist.(exit 1)
Hyper-V cmdletLinux lab equivalent
New-VMSwitchip link add vswitch0 type bridge
Get-VMSwitchip -d link show vswitch0 / bridge link
Get-VMNetworkAdapterVlanbridge vlan show
Rename-VMNetworkAdapterip link set eth0 name corenet
Remove-VMNetworkAdapterip link del vm3-p
Remove-VMSwitchip link del vswitch0

261.8 Common mistakes

  • Passing -SwitchType External: only Internal/Private are allowed; give -NetAdapterName instead.
  • Running Rename-VMNetworkAdapter without -Name on a multi-NIC VM renames every adapter.
  • Expecting Remove-VMNetworkAdapterAcl to work without both -Action and -Direction.
  • Trying to remove an extension feature that was never configured.

261.9 Interview tips

  • Separate VMs by VLAN: Set-VMNetworkAdapterVlan -Access -VlanId, verify with Get-VMNetworkAdapterVlan, then ping same VLAN (ok) and other VLAN (fails).
  • Know the three switch types: External, Internal, Private, and who can reach whom.
  • Extensions run in order capture -> filter -> forward.
  • Feature cmdlets = configuration, Data cmdlets = runtime stats.