4 Replies Latest reply on Oct 11, 2008 2:17 AM by LucD

    Port Group Types

    cody.bunch Hot Shot

       

      Greetings Powershell VI-Toolkit folks!

       

       

      Is there a way to tell what Type a port group is? Say a Service Console or VMKernel port group?  This would be rather useful.

       

       

      -Cody

       

       

       

       

       

        • 1. Re: Port Group Types
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          Something quick and dirty.

          It will show for an ESX host the switchname, portgroup and the portgroup type.

          $net = Get-View -id (Get-VMHost -Name <ESX-name> | Get-View).ConfigManager.NetworkSystem
          foreach($pg in $net.NetworkInfo.Portgroup){
            if($pg.Port -eq $null) {
              Write-Host $pg.Spec.VswitchName $pg.Spec.Name "Virtual Machine Port Group"}
            else {Write-Host $pg.Spec.VswitchName $pg.Spec.Name $pg.Port[0].Type}
          }
          

           

          Note that it will give a type of "host" for VMkernel port groups.

          • 2. Re: Port Group Types
            cody.bunch Hot Shot

             

            Yeah... umm...

             

             

            WOW

             

             

            • 3. Re: Port Group Types
              halr9000 Master

              He has that effect.

               

              Author of the upcoming book: Managing VMware Infrastructure with PowerShell

              Co-Host, PowerScripting Podcast (http://powerscripting.net)

              • 4. Re: Port Group Types
                LucD Guru
                vExpertCommunity WarriorsUser Moderators

                Well it seems my previous script was mostly "dirty", there is a problem with that script.

                For the explanation of the problem see  Re: Get list of available networks on an ESX host.

                 

                This should be a "working" script.

                
                $netsystem = Get-View -id (Get-VMHost -Name <ESX-name> | Get-View).ConfigManager.NetworkSystem
                $noVMnic = @{}
                foreach($vnic in $netsystem.NetworkInfo.ConsoleVnic){ 
                  $noVMnic[http://$vnic.Portgroup|http://$vnic.Portgroup] = $true
                } 
                foreach($vnic in $netsystem.NetworkInfo.Vnic){ 
                  $noVMnic[http://$vnic.Portgroup|http://$vnic.Portgroup] = $true
                } 
                 
                foreach($pg in $netsystem.NetworkInfo.Portgroup){ 
                  if(! $noVMnic.ContainsKey($pg.Spec.Name)){
                    Write-Host $pg.Spec.VswitchName $pg.Spec.Name "Virtual Machine Port Group"
                  }
                  else{
                    Write-Host $pg.Spec.VswitchName $pg.Spec.Name $pg.Port[0].Type
                  }
                } 
                
                

                 

                Since the forum SW seems to have problems with square brackets I attached the script.