VMware

This Question is Answered

2 "helpful" answers available (6 pts)
4 Replies Last post: Oct 11, 2008 2:14 AM by LucD  

Port Group Types posted: Aug 20, 2008 10:36 AM

Click to view cody.bunch's profile Hot Shot 152 posts since
Dec 28, 2007

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


Re: Port Group Types

1. Aug 20, 2008 11:38 AM in response to: cody.bunch
Click to view LucD's profile Champion 2,443 posts since
Oct 31, 2005
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.

Re: Port Group Types

3. Aug 20, 2008 5:02 PM in response to: cody.bunch
Click to view halr9000's profile Master 814 posts since
Jun 7, 2007
He has that effect.

Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)

Re: Port Group Types

4. Oct 11, 2008 2:17 AM in response to: LucD
Click to view LucD's profile Champion 2,443 posts since
Oct 31, 2005
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:

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities