Skip navigation
VMware

This Question is Answered (go to answer)

2 "helpful" answers available (6 pts)
2,932 Views 4 Replies Last post: Oct 11, 2008 2:17 AM by LucD RSS
cody.bunch Hot Shot vExpert 238 posts since
Dec 28, 2007
Currently Being Moderated

Aug 20, 2008 10:36 AM

Port Group Types

 

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

 

 

 

 

 

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
1. Aug 20, 2008 11:38 AM in response to: cody.bunch
Re: Port Group Types

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.

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
halr9000 Master vExpert 1,124 posts since
Jun 7, 2007
Currently Being Moderated
3. Aug 20, 2008 5:02 PM in response to: cody.bunch
Re: Port Group Types

He has that effect.

 

Author of the upcoming book: Managing VMware Infrastructure with PowerShell

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

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
4. Oct 11, 2008 2:17 AM in response to: LucD
Re: Port Group Types

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.

Attachments:
Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com

Bookmarked By (0)

Share This Page

Communities