Note: This tip requires PowerShell 3.0 or above.
In a physical switch environment, all traffic from selected ports can be duplicated and copied to a mirror port for capture and analysis, such as network diagnostic of a VM boot process or any network-related issues.
Starting in Windows Server 2012, port mirroring can be enabled on virtual switches as well. We can designate a vSwitch port as a monitoring port, and direct the vSwitch traffic going through this port to a specific VM.
The configuration is twofold–changes are needed on both, the source and destination VMs. This can be set under the Advanced Features page of the VMs’ network card.
The following commands sets port mirroring on two VMs using the Set-VMNetworkAdapter. VM1 acts as the source VM, every packet sent or received by VM1 (on all all virtual network adapters) will be mirrored to VM2 virtual network card named Public . When you open a network monitor application on VM2, you will see captured traffic from both VMs.
Set-VMNetworkAdapter -VMName VM1 -PortMirroring Source Set-VMNetworkAdapter -VMName VM2 -Name Public -PortMirroring Destination
Note that you can set multiple VMs as source machines and all their traffic will be copied to the destination VM.