VMware Communities > Developer Community > VI Toolkit (for Windows) > Discussions

This Question is Answered

1 "correct" answer available (10 pts) 1 "helpful" answer available (6 pts)
2 Replies Last post: Nov 23, 2008 10:10 AM by PeterVG
Reply

List VM's that are connected to more than 1 Portgroup

Nov 23, 2008 1:11 AM

Click to view PeterVG's profile Novice PeterVG 9 posts since
Nov 29, 2004

Hi all,

We have a DMZ Vmware cluster & for security reasons our security guys want to be informed on a daily basis if there have been VM's configured with 2 network connections, something they don't allow...

So am trying to do this with Powershell: my idea was to have a script output all the VM's with more than 1 portgroup & possibly listing all the portgroups to which it is attached.

The problem is that I don't know how to filter the VM's with 1 PG connection with the ones that have 2 or more connections.
Anybody an idea ?

Thanks in advance !
Peter

Reply Re: List VM's that are connected to more than 1 Portgroup Nov 23, 2008 3:29 AM
Click to view LucD's profile Master LucD 858 posts since
Oct 31, 2005
This script prints all guests that have more than 1 network connection.
$vms = Get-VM
foreach($vm in $vms){
  $pgs = Get-VirtualPortGroup -VM $vm | select Name
  if($pgs.Count -gt 1){
   $pgsLine = ""
   foreach($pg in $pgs){
     $pgsLine += ($pg.Name + " ")
   }
   Write-Host $vm.Name $pgsLine
  }
}

Or you could use a one-liner that shows the guestname and the number of portgroups it is connected too.
Get-VM | %{$vm = $_.Name; Get-VirtualPortGroup -VM $_ | Measure-Object | %{Write-Host $vm $_.Count}}

And you can include a filter to only display the guests with more than 1 portgroup.
Get-VM | %{$vm = $_.Name; Get-VirtualPortGroup -VM $_ | Measure-Object | where {$_.Count -gt 1} | %{Write-Host $vm $_.Count}}
Reply Re: List VM's that are connected to more than 1 Portgroup Nov 23, 2008 10:10 AM
in response to: LucD
Click to view PeterVG's profile Novice PeterVG 9 posts since
Nov 29, 2004

Luc

je bent echt geweldig !! ;-)
You're truly great ;-)

Thanks a million, you saved me a lot of time !!

Peter


Actions