List all VM's by their port mirroring settings PowerShell

766 views Asked by At

I'm looking for a way to list all VM's on a machine by the type of mirroring they have set using PowerShell.

For Example:

Get-VM -PortMirroring Source

And I'll see all VM's that have network adapters with Port Mirroring set to Source. But I know that Get-VM doesn't take PortMirroring as a parameter, so I'm wondering if there is a workaround?

2

There are 2 answers

1
Vesper On BEST ANSWER

This is not this easy, as PortMirroring is not the property of a VM, but rather a property of its network adapter. You need to iterate VMs' network adapters and output VMs that have at least 1 adapter that has PortMirroringMode set to "Source".

$vms=get-vm
$filteredVMs=@()
foreach ($vm in $vms) { 
   $nas=get-vmnetworkadapter -vm $vm # adapter list
   foreach ($na in $nas) {
       if ($na.PortMirroringMode -eq 'Source') {
           $filteredVMs+=$vm
           break 
       }
   }
}
0
rofz On

This works for me:

get-vm | Get-VMNetworkAdapter | Where-Object {$_.PortMirroringMode -eq 'Source'}