VMware Cloud Community
StuartB20111014
Enthusiast
Enthusiast
Jump to solution

I need to get all the VLAN data from entire Vcenters worth of clusters

Hiya,

I know my good will is probabily getting a bit short here but hey I shall ask!

I have several vcenters, with hundreds of vlans (literally)

What I need to do is to extract, per cluster:

Cluster name

Network ranges available within the cluster

VLAN ID

As I say, if anyone can provide a script to do that, it would be much appreciated.

Regards

Stu

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Sure, capture the output in a variable and pipe that variable to the Export-Csv cmdlet.

$report = foreach($cluster in Get-Cluster){
    foreach($esx in (Get-VMHost -Location $cluster)){
        foreach($pg in (Get-VirtualPortgroup -VMHost $esx)){
            Select -InputObject $pg @{N="Cluster";E={$cluster.Name}},
            @{N="VMHost";E={$esx.Name}},
            @{N="Portgroup";E={$pg.Name}},
            @{N="VLAN";E={$pg.VlanId}},
            @{N="IP";E={
                    $adapter = Get-VMHostNetworkAdapter -VMHost $esx | where {$_.PortgroupName -eq $pg.Name} 
                    if($adapter){
                        [string]::Join(',',($adapter.IP | %{$_}))
                    }
                }}
        }
    }
}

$report | Export-Csv "C:\Temp\report.csv" -NoTypeInformation -UseCulture


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

View solution in original post

0 Kudos
5 Replies
Virtualinfra
Commander
Commander
Jump to solution

Use RVTOOL if you have not used before.. its a freeware.. which will fetch you the required information..under vNetwork and vSwitch column..

link to download rvtool

http://www.robware.net/

Award points by clicking the below tab if the answer is helpful and correct Smiley Happy

Thanks & Regards Dharshan S VCP 4.0,VTSP 5.0, VCP 5.0
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could try something like this

foreach($cluster in Get-Cluster){
    foreach($esx in (Get-VMHost -Location $cluster)){
        foreach($pg in (Get-VirtualPortgroup -VMHost $esx)){
            Select -InputObject $pg @{N="Cluster";E={$cluster.Name}},
            @{N="VMHost";E={$esx.Name}},
            @{N="Portgroup";E={$pg.Name}},
            @{N="VLAN";E={$pg.VlanId}},
            @{N="IP";E={
                    $adapter = Get-VMHostNetworkAdapter -VMHost $esx | where {$_.PortgroupName -eq $pg.Name} 
                    if($adapter){
                        [string]::Join(',',($adapter.IP | %{$_}))
                    }
                }}
        }
    }
}


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

0 Kudos
vmhyperv
Contributor
Contributor
Jump to solution

LucD,

   Can it be exported in csv format all vlan info.

thanks

vmguy

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, capture the output in a variable and pipe that variable to the Export-Csv cmdlet.

$report = foreach($cluster in Get-Cluster){
    foreach($esx in (Get-VMHost -Location $cluster)){
        foreach($pg in (Get-VirtualPortgroup -VMHost $esx)){
            Select -InputObject $pg @{N="Cluster";E={$cluster.Name}},
            @{N="VMHost";E={$esx.Name}},
            @{N="Portgroup";E={$pg.Name}},
            @{N="VLAN";E={$pg.VlanId}},
            @{N="IP";E={
                    $adapter = Get-VMHostNetworkAdapter -VMHost $esx | where {$_.PortgroupName -eq $pg.Name} 
                    if($adapter){
                        [string]::Join(',',($adapter.IP | %{$_}))
                    }
                }}
        }
    }
}

$report | Export-Csv "C:\Temp\report.csv" -NoTypeInformation -UseCulture


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

0 Kudos
vmhyperv
Contributor
Contributor
Jump to solution

Thanks LucD !!

0 Kudos