2 Replies Latest reply on Nov 23, 2008 10:10 AM by PeterVG

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

    PeterVG Enthusiast

       

      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

       

       

        • 1. Re: List VM's that are connected to more than 1 Portgroup
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          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}}
          

           

          1 person found this helpful
          • 2. Re: List VM's that are connected to more than 1 Portgroup
            PeterVG Enthusiast

             

            Luc

             

             

            je bent echt geweldig !!

            You're truly great

             

             

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

             

             

            Peter