SkillPilotAI

PowerShell Hyper-V networking cmdlets (3/3)

Part 3 of the Hyper-V networking cmdlets: Rename-VMSwitch, the Set-* cmdlets that change live switch and adapter settings (MAC, guards, bandwidth, VLAN, isolation, teaming, failover IP, extension features) and Test-VMNetworkAdapter to check connectivity between VMs.

262.1 Why is it used?

  • Set-* cmdlets change existing switches and adapters without recreating them.
  • Security: DhcpGuard, RouterGuard, MacAddressSpoofing and isolation stop a bad VM from hurting others.
  • Performance: bandwidth limits/guarantees, VMQ, vRSS and SR-IOV tuning.
  • Test-VMNetworkAdapter proves two VMs can actually reach each other.
  • The Hyper-V module comes with the Hyper-V feature (Windows 10/11 Pro, Windows Server); on the video's office PC the module count was 0, so syntax is from Microsoft Learn and the lab is a Linux equivalent.

262.2 Rename-VMSwitch

  • -Name is the old name, -NewName the new name (both required); or pass the switch object with -VMSwitch.
  • -Passthru returns the EthernetSwitch object; -ComputerName / -Credential for a remote host.
PowerShell
Rename-VMSwitch "QoS Switch" -NewName "IIS Switch"
  • Linux idea: ip link set vswitch0 name labswitch; both VM ports now show master labswitch and ping still works.
Terminal
ip -br link show type bridgeip link set vswitch0 name labswitchbridge linkip netns exec vm1 ping -c 2 -W 1 192.168.62.12
Output
[hvhost]$ bridge link4: vm1-port@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master labswitch state forwarding priority 32 cost 25: vm2-port@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master labswitch state forwarding priority 32 cost 2[hvhost]$ ip netns exec vm1 ping -c 2 -W 1 192.168.62.1264 bytes from 192.168.62.12: icmp_seq=1 ttl=64 time=0.073 ms64 bytes from 192.168.62.12: icmp_seq=2 ttl=64 time=0.086 ms--- 192.168.62.12 ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 1031ms

262.3 Set-VMNetworkAdapter (46 options)

GroupKey optionsWhat it does
MAC and guards-StaticMacAddress, -DynamicMacAddress, -MacAddressSpoofing, -DhcpGuard, -RouterGuardFixed MAC; drop fake DHCP replies and rogue router advertisements
Mirroring-PortMirroring None|Source|DestinationCopy one VM's traffic to a monitoring VM
Bandwidth-MaximumBandwidth, -MinimumBandwidthAbsolute, -MinimumBandwidthWeight, -StormLimitUpper limit, guaranteed minimum, broadcast/multicast limit per sec
Queues / offload-VmqWeight, -VrssEnabled, -VmmqEnabled, -IovWeight, -IeeePriorityTagVMQ, vRSS, SR-IOV VF, 802.1p trust
Other-AllowTeaming, -VirtualSubnetId, -TestReplicaSwitchName, -DeviceNaming, -NotMonitoredInClusterGuest NIC teaming, HNV subnet, test failover switch
Target-VMName, -VM, -VMNetworkAdapter, -ManagementOS, -NameWhich VM / host vNIC / adapter
PowerShell
Set-VMNetworkAdapter -VMName Redmond -DhcpGuard OnSet-VMNetworkAdapter -VMName Kirkland -PortMirroring SourceSet-VMNetworkAdapter -VMName Bellevue -Name PM_Dest -PortMirroring DestinationGet-VMNetworkAdapter -VMName Redmond,Kirkland,Bellevue | Set-VMNetworkAdapter -MinimumBandwidthWeight 1Get-VMNetworkAdapter -All | Set-VMNetworkAdapter -VmqWeight 100Get-VM Redmond | Set-VMNetworkAdapter -AllowTeaming On
  • Lab idea (StaticMacAddress): set vm1's eth0 MAC to 02:62:00:00:00:11 and MTU 1400; after a ping the new MAC appears in vm2's neighbor table and the bridge FDB.
  • Bandwidth (tc qdisc on Linux) stayed docs-only because it would load a kernel module in the lab.
Terminal
ip -n vm1 link set eth0 address 02:62:00:00:00:11ip -n vm1 link set eth0 mtu 1400ip -n vm2 neigh flush allip netns exec vm1 ping -c 2 -W 1 192.168.62.12ip -n vm2 neigh showbridge fdb show br labswitch | grep 02:62
Output
[hvhost]$ ip -n vm2 neigh show192.168.62.11 dev eth0 lladdr 02:62:00:00:00:11 DELAY[hvhost]$ bridge fdb show br labswitch | grep 02:6202:62:00:00:00:11 dev vm1-port master labswitch
Why ping fails with learning off + flood off
  1. 1.vm1-port: learning off, flood off; old FDB entry deleted

  2. 2.vm1 pings vm2; the bridge does not learn vm1's MAC

  3. 3.vm2 replies to an unknown unicast MAC

  4. 4.Bridge cannot flood it to vm1-port -> 100% loss

  5. 5.learning on flood on -> ping works again

Terminal
bridge link set dev vm1-port learning offbridge link set dev vm1-port flood offbridge fdb del 02:62:00:00:00:11 dev vm1-port masterip netns exec vm1 ping -c 2 -W 1 192.168.62.12bridge link set dev vm1-port learning on flood onip netns exec vm1 ping -c 2 -W 1 192.168.62.12

262.4 Isolation and routing domains

  • Isolation: VMs of different tenants cannot reach each other even on the same switch.
  • Set-VMNetworkAdapterIsolation -IsolationMode None|NativeVirtualSubnet|ExternalVirtualSubnet|Vlan.
  • Docs example: TSQA01 in VLAN mode accepts untagged traffic on VLAN 1 (-AllowUntaggedTraffic, -DefaultIsolationID 1, -MultiTenantStack On).
  • Set-VMNetworkAdapterRoutingDomainMapping sets virtual subnets of a routing domain on a multitenant VM (IsolationID 6001 on Gateway01).
  • Linux idea: bridge port flag isolated on; two isolated ports never forward to each other.
PowerShell
Set-VMNetworkAdapterIsolation -VMName "TSQA01" -AllowUntaggedTraffic $True -IsolationMode VLAN -DefaultIsolationID 1 -MultiTenantStack OnSet-VMNetworkAdapterRoutingDomainMapping -VMName "Gateway01" -VMNetworkAdapterName "Internal NIC" -RoutingDomainID "{5a07361e-6a54-49fc-9210-bfbf14a5c56f}" -IsolationID 6001
Terminal
bridge link set dev vm1-port isolated onbridge link set dev vm2-port isolated onip netns exec vm1 ping -c 3 -W 1 192.168.62.12   # 100% lossbridge link set dev vm1-port isolated offbridge link set dev vm2-port isolated offip netns exec vm1 ping -c 3 -W 1 192.168.62.12
Output
[hvhost]$ ip netns exec vm1 ping -c 3 -W 1 192.168.62.1264 bytes from 192.168.62.12: icmp_seq=1 ttl=64 time=0.103 ms64 bytes from 192.168.62.12: icmp_seq=2 ttl=64 time=0.123 ms64 bytes from 192.168.62.12: icmp_seq=3 ttl=64 time=0.152 ms--- 192.168.62.12 ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2028ms

262.5 Set-VMNetworkAdapterVlan

ModeOptionsMeaning
Access-VlanId 121VM traffic is in one VLAN (121)
Trunk-AllowedVlanIdList 1-100 -NativeVlanId 10Many VLANs; untagged traffic goes to VLAN 10
Isolated / Community-PrimaryVlanId 10 -SecondaryVlanId 200Private VLAN secondary ports
Promiscuous-PrimaryVlanId 10 -SecondaryVlanIdList 200-201Private VLAN port that talks to all secondaries
Untagged(none)Remove VLAN tagging
PowerShell
Set-VMNetworkAdapterVlan -VMName Redmond -Access -VlanId 121Set-VMNetworkAdapterVlan -VMName Redmond -Trunk -AllowedVlanIdList 1-100 -NativeVlanId 10Get-VM Redmond | Set-VMNetworkAdapterVlan -UntaggedSet-VMNetworkAdapterVlan -ManagementOS -Access -VlanID 20
  • Lab: vlan_filtering 1 on labswitch (no new kernel module loaded), vm1 + vm2 access VLAN 10 -> ping ok; vm2 moved to VLAN 20 -> 100% loss; back to 10 -> recovers.
Terminal
ip link set labswitch type bridge vlan_filtering 1bridge vlan add dev vm1-port vid 10 pvid untaggedbridge vlan del dev vm2-port vid 10bridge vlan add dev vm2-port vid 20 pvid untaggedbridge vlan showip netns exec vm1 ping -c 3 -W 1 192.168.62.12
Output
[hvhost]$ bridge vlan show dev vm2-portport              vlan-idvm2-port          10 PVID Egress Untagged[hvhost]$ ip netns exec vm1 ping -c 3 -W 1 192.168.62.1264 bytes from 192.168.62.12: icmp_seq=1 ttl=64 time=0.124 ms64 bytes from 192.168.62.12: icmp_seq=2 ttl=64 time=0.111 ms64 bytes from 192.168.62.12: icmp_seq=3 ttl=64 time=0.091 ms--- 192.168.62.12 ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2054ms

262.6 Set-VMSwitch and Set-VMSwitchTeam

  • Set-VMSwitch changes 19 settings of the whole switch: -SwitchType, -NetAdapterName (becomes External), -AllowManagementOS, default flow bandwidth, -Notes.
  • -DefaultFlowMinimumBandwidthAbsolute 500000000 gives the other VMs a 500 Mbps minimum.
  • Set-VMSwitchTeam -LoadBalancingAlgorithm HyperVPort|Dynamic for a SET team.
  • Linux idea: ip link set type bridge ageing_time 1000 (10 s, centiseconds) and stp_state 1.
PowerShell
Set-VMSwitch WA -SwitchType InternalSet-VMSwitch VMNetwork -NetAdapterName "Ethernet 2"Set-VMSwitch CA -DefaultFlowMinimumBandwidthAbsolute 500000000Set-VMSwitchTeam -Name "SwitchTeam07" -LoadBalancingAlgorithm Dynamic
Terminal
ip link set labswitch type bridge ageing_time 1000ip link set labswitch type bridge stp_state 1ip netns exec vm1 ping -c 2 -W 1 192.168.62.12ip link set labswitch type bridge stp_state 0ip -d link show labswitch | grep -o 'ageing_time [0-9]*\|stp_state [0-9]'
Output
ageing_time 1000stp_state 0

262.7 Failover IP, team mapping and extension features

Hyper-V Replica failover IP
  1. 1.VM01 runs on the primary host as 192.168.10.50

  2. 2.Replication keeps a copy on the replica host

  3. 3.Primary site goes down

  4. 4.VM01 starts on the replica host in another subnet

  5. 5.It uses the failover IP 10.100.1.100; client traffic reaches it via the router

Set with Set-VMNetworkAdapterFailoverConfiguration

  • Set-VMNetworkAdapterFailoverConfiguration: -IPv4Address/-IPv4SubnetMask/-IPv4DefaultGateway/DNS and IPv6 versions; -ClearFailoverIPv4Settings goes back to the primary IP.
  • Set-VMNetworkAdapterTeamMapping maps a VM adapter to one physical NIC of a SET team (docs example empty, syntax only).
  • Set-VMSwitchExtensionPortFeature / SwitchFeature change an already-configured feature: read it, edit SettingData, set it back.
PowerShell
Get-VMNetworkAdapter VM01 NetworkAdapter01 | Set-VMNetworkAdapterFailoverConfiguration -IPv4Address 10.100.1.100 -IPv4SubnetMask 255.255.255.0$ModifiedFeature = Get-VMSwitchExtensionPortFeature -VMName VM2 -FeatureName "Ethernet Switch Port Security Settings"$ModifiedFeature.SettingData.EnableDhcpGuard = $falseSet-VMSwitchExtensionPortFeature -VMName VM2 -VMSwitchExtensionFeature $ModifiedFeature$feature = Get-VMSystemSwitchExtensionSwitchFeature -FeatureName "Ethernet Switch Bandwidth Settings"$feature.SettingData.DefaultFlowReservation = 100000000Set-VMSwitchExtensionSwitchFeature External $feature

262.8 Test-VMNetworkAdapter

  • Tests connectivity between two VMs with ICMP ping packets.
  • -Sender | -Receiver: which VM the cmdlet targets; -SenderIPAddress and -ReceiverIPAddress are required.
  • -SequenceNumber (default 100), -PayloadSize, -NextHopMacAddress (non-HNV), -IsolationId (virtual subnet).
  • Linux idea: ping with -I sender address, -c count, -s payload size.
PowerShell
Test-VMNetworkAdapter -VMName "ContosoVM01" -Receiver -SenderIPAddress "10.20.20.5" -ReceiverIPAddress "10.20.20.6" -VMNetworkAdapterName "ContosoNic01"
Terminal
ip netns exec vm1 ping -c 4 -I 192.168.62.11 -s 100 192.168.62.12
Output
PING 192.168.62.12 (192.168.62.12) from 192.168.62.11 : 100(128) bytes of data.108 bytes from 192.168.62.12: icmp_seq=1 ttl=64 time=0.122 ms108 bytes from 192.168.62.12: icmp_seq=2 ttl=64 time=0.092 ms108 bytes from 192.168.62.12: icmp_seq=3 ttl=64 time=0.185 ms108 bytes from 192.168.62.12: icmp_seq=4 ttl=64 time=0.115 ms--- 192.168.62.12 ping statistics ---4 packets transmitted, 4 received, 0% packet loss, time 3073msrtt min/avg/max/mdev = 0.092/0.128/0.185/0.034 ms

262.9 Common mistakes

  • Assuming VMs on the same vSwitch can always talk: VLAN, isolation and ACLs can block them.
  • Moving a VM to a new VLAN but forgetting to allow that VLAN on the physical switch trunk.
  • Trying Set-VMSwitchExtension*Feature on a feature that is not configured yet.
  • Running Set-* on a production host without checking the current values first (Get-* before Set-*).

262.10 Interview tips

  • Same switch + same subnet but ping fails: check VLAN first (Get-VMNetworkAdapterVlan), then isolation and port flags.
  • Move a VM to VLAN 20: Set-VMNetworkAdapterVlan -Access -VlanId 20, allow VLAN 20 on the trunk, confirm with Get-VMNetworkAdapterVlan, test with ping.
  • DhcpGuard and RouterGuard protect against rogue DHCP servers and router advertisements from a VM.
  • Verify connectivity with Test-VMNetworkAdapter or ping, never from the switch name.