VMware Cloud Community
vmCalgary
Enthusiast
Enthusiast
Jump to solution

Portgroup vlan list by esxihost

I am looking for some help gathering a list of portgroups and vlans by cluster & vmhost.

Desired column headers:

Cluster

VMhost

Portgroup

vlan

vcenter

Counts of VMs and VMHosts per cluster is a 'would be nice' to have as well.

 

0 Kudos
1 Solution

Accepted Solutions
mpeneva
VMware Employee
VMware Employee
Jump to solution

Sorry for the extra bracket in the second line. Below is my suggestion:

$vcConnection = Connect-VIServer -Server <server_IP? -User <user_name> -Password <user_password>
$dc = Get-Datacenter -Server $vcConnection
$objects = $dc | Get-VMHost -Server $vcConnection| Get-VirtualPortGroup -Server $vcConnection

foreach($obj in $objects) {
$clusterResult = $dc | Get-Cluster -Server $vcConnection
foreach ($cluster in $clusterResult) {
$vmHost = $cluster | Get-VMHost
$vmHost | Get-VirtualPortGroup | ? {$_.Name -eq $obj.Name} | select @{N='Datacenter'; E = {$dc.Name}}, @{N = 'Portgroup'; E = {$obj.Name}}, @{N = 'VLanId'; E = {$obj.VLanId}}, @{N = 'ClusterName'; E = {$cluster.Name}}, @{N = 'VCenter' ; E={$vcConnection}}, @{N = 'VMHostCount'; E = {$vmHost.Count}}, @{N = 'VMCount'; E = {($vmHost|Get-VM).Count}}
}
}

 

View solution in original post

6 Replies
LucD
Leadership
Leadership
Jump to solution

What do you already have?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
vmCalgary
Enthusiast
Enthusiast
Jump to solution

I found this on one of your replies, LucD. I don't really need the details for each vmhost  as per cluster was good enough. I guess I didn't do enough sleuthing before I posted.
 
Get-Datacenter -PipelineVariable dc |

Get-Cluster -PipelineVariable cluster |

Get-VMHost |

Get-VirtualPortGroup |

  Select @{N = 'Datacenter'; E = {$dc.Name}},

   @{N = 'Cluster'; E = {$cluster.Name}},

  Name, VlanId,

   @{N = 'VMCount'; E = {($_ | Get-VM).Count}} |

Group-Object -Property Datacenter, Cluster, Name |

ForEach-Object -Process {

   $_ | Select @{N = 'Datacenter'; E = {$_.Name.Split(',')[0].Trim(' ')}},

   @{N = 'Cluster'; E = {$_.Name.Split(',')[1].Trim(' ')}},

   @{N = 'Portgroup'; E = {$_.Name.Split(',')[2].Trim(' ')}},

   @{N = 'VlanId'; E = {$_.Group[0].VlanId}},

   @{N = 'VMHostCount'; E = {$_.Count}},

   @{N = 'VMCount'; E = {($_.Group | Measure-Object -Property VMCount -Sum).Sum}}

}

0 Kudos
mpeneva
VMware Employee
VMware Employee
Jump to solution

I have made some modifications of Luc's script:

$vcConnection = Connect-VIServer -Server <server_IP? -User <user_name> -Password <user_password>
$dc = (Get-Datacenter -Server $vcConnection
$objects = $dc | Get-VMHost -Server $vcConnection| Get-VirtualPortGroup -Server $vcConnection

foreach($obj in $objects) {
$dc | Get-VMHost | Get-VirtualPortGroup | ? {$_.Name -eq $obj.Name} | select @{N='Datacenter';'E' = {$dc.Name}},@{N = 'Portgroup'; E = {$obj.Name}}, @{N = 'VLanId'; E = {$obj.VLanId}}
}

Does this work for you ?

Tags (1)
0 Kudos
vmCalgary
Enthusiast
Enthusiast
Jump to solution

Not entirely. The second line was missing the closing bracket and the cluster information was missing. This is to be used as part of a lifecycle replacement project.

0 Kudos
mpeneva
VMware Employee
VMware Employee
Jump to solution

Sorry for the extra bracket in the second line. Below is my suggestion:

$vcConnection = Connect-VIServer -Server <server_IP? -User <user_name> -Password <user_password>
$dc = Get-Datacenter -Server $vcConnection
$objects = $dc | Get-VMHost -Server $vcConnection| Get-VirtualPortGroup -Server $vcConnection

foreach($obj in $objects) {
$clusterResult = $dc | Get-Cluster -Server $vcConnection
foreach ($cluster in $clusterResult) {
$vmHost = $cluster | Get-VMHost
$vmHost | Get-VirtualPortGroup | ? {$_.Name -eq $obj.Name} | select @{N='Datacenter'; E = {$dc.Name}}, @{N = 'Portgroup'; E = {$obj.Name}}, @{N = 'VLanId'; E = {$obj.VLanId}}, @{N = 'ClusterName'; E = {$cluster.Name}}, @{N = 'VCenter' ; E={$vcConnection}}, @{N = 'VMHostCount'; E = {$vmHost.Count}}, @{N = 'VMCount'; E = {($vmHost|Get-VM).Count}}
}
}

 

vmCalgary
Enthusiast
Enthusiast
Jump to solution

Perfection. Thanks for your help.