BlackHawk-VM
Contributor
Contributor

VMs on a Port Group for a Specific ESX Host

In a VI Client I can go to the Configuration page of an ESX host and under Networking see the count and names of all VMs attached to a port group.

How can a similar report be generated via PowerShell?

0 Kudos
2 Replies
hugopeeters
Hot Shot
Hot Shot

Try adapting my example here ( http://www.peetersonline.nl/index.php/vmware/how-many-vms-in-each-lan/ ) for use on a single esx host. You could also connect to the esx server instead of to the VC server.

0 Kudos
LucD
Leadership
Leadership

You can try this

$esxName = <esxname>
$pgName = <portgroup-name>
$vms = Get-VMHost -Name $esxName | Get-VM
$number = $vms | %{Get-VirtualPortGroup -VM $_ -Name $pgName} | Measure-Object | %{$_.Count}
$guests = $vms | %{if(Get-VirtualPortGroup -VM $_ -Name $pgName) {$_.Name}}
Write-Host $number $guests


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos