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}}
}
Try like this
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
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}}
}
}
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
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
}
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