VMware Cloud Community
ktitchard
Contributor
Contributor

Trying to get a list of VLANs on a Cluster

Hi all

I am trying to extract the list of Networks associated to a Cluster. I have managed to get the VLANs but I cant seem to tie them to a cluster. Its driving me nuts please help.

So far I Have

 

$DSwitches = Get-Datacenter -name UK | Get-VDSwitch

    foreach ($DSwitch in $DSwitches) {

        Get-Datacenter -name UK | Get-VDSwitch -Name $DSWitch | Get-VDPortgroup | Select Name,@{Name='DSwitchName';Expression={$DSWitch.Name}}

        }

0 Kudos
5 Replies
LucD
Leadership
Leadership

Try like this

Get-Datacenter -name UK | Get-VDSwitch |

Get-VDPortgroup |

Select Name,

   @{Name='DSwitchName';Expression={$_.VDSwitch.Name}},

   @{N='Cluster';E={(Get-VMHost -DistributedSwitch $_.VDSwitch | Get-Cluster).Name}}


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

0 Kudos
ktitchard
Contributor
Contributor

Thanks for the reply. I tried the above script and the cluster column is empty.

I think I managed to solve it now

 

$a = Get-Datacenter UK | Get-Cluster

   foreach ($b in $a) {

     foreach ($DSwitch in $DSwitches) {

        if ($DSwitch.name -match $b.name) {

        Get-Datacenter -name UK | Get-VDSwitch -Name $DSWitch | Get-VDPortgroup | Select Name,@{Name='DSwitchName';Expression={$DSWitch.Name}},@{Name='Cluster';Expression={$b}}

            }

        }

0 Kudos
LucD
Leadership
Leadership

Not sure how you run these scripts, but the one I gave is working.

The one you include is not working.


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

0 Kudos
ktitchard
Contributor
Contributor

Sorry here is the entire code

#Varibales
$VCentres = ''


#$credentials = get-Credential

#Arrays
$ClusterList =@()
$ClusterVLAN =@()


#Load Modules
Import-module vmware.vimautomation.core
Import-Module VMware.VimAutomation.Vds

Foreach ($VC in $VCentres){

Connect-VIServer -Server $VC -Credential $credentials

    $Clusters = Get-Cluster | Select Name,@{Name='VCentre';Expression={$VC}}

        $ClusterList += $Clusters


            Disconnect-VIServer -Server $VC -Confirm:$False


$DSwitches = Get-Datacenter -name UK | Get-VDSwitch


$ClusterList | export-csv C:\temp\all_clusters.csv -NoTypeInformation -Encoding UTF8


$DSwitches = Get-Datacenter -name UK | Get-VDSwitch

$a = Get-Datacenter UK | Get-Cluster


     foreach ($b in $a) {

     foreach ($DSwitch in $DSwitches) {

        if ($DSwitch.name -match $b.name) {

        $VLANS = Get-Datacenter -name UK | Get-VDSwitch -Name $DSWitch | Get-VDPortgroup | Select Name,@{Name='DSwitchName';Expression={$DSWitch.Name}},@{Name='Cluster';Expression={$b}}

        $ClusterVLAN += $VLANS

        }

        }

     }

 $ClusterVLAN | export-csv C:\temp\all_vlans.csv -NoTypeInformation -Encoding UTF8

}

0 Kudos
LucD
Leadership
Leadership

I guess there is more than 1 road to reach Rome, but if it works for you, it's a good script :smileygrin:


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

0 Kudos