VMware Cloud Community
faherne_CTI
Enthusiast
Enthusiast
Jump to solution

Looking to query multipe vCenters to identify if Cluster hosts are configured with vDS or vSS

I'm looking to to query multiple vCenters and each's associated clusters to identify which clusters are configured with vSS or vDSs with an outputted CSV file similar to:

| vCenterName | ClusterName | ESXi Version | Using vDS (True/False) | Using vSS (True/False) |

This is my idea for what I'm looking for with the code, but I'm looking to find out if someone has a better, smarter or simpler way of querying cluster hosts for vDS/vSS:

$vCs = (GetContent import-CSV .\vCenterList.csv)

Connect-ViServer $vCs

$Report = Foreach ($vC in $vCs){

  $VMHosts = get-cluster | get-vmhost | Select First 1 |

  Foreach ($ESXiHost in $VMHosts) {

     If ((Get-VirtualPortGroup -VMHost $ESXiHost).Count -GE 1) | Select {

      @{ N = "vC Name "; E =  $vC },

      @{ N = "Cluster Name "; E = {$ESXiHost.Parent} },

      @{ N = "ESXi Version"; E = {$ESXiHost.Version} },

      @{ N = "Using vDS"; E = "False" },

      @{ N = "Using vSS"; E = "True" }

    }

    ElseIf ((Get-VirtualPortGroup -VMHost $ESXiHost).Count -GE 1) | Select {

      @{ N = "vC Name "; E =  $vC },

      @{ N = "Cluster Name "; E = {$ESXiHost.Parent} },

      @{ N = "ESXi Version"; E = {$ESXiHost.Version} },

      @{ N = "Using vDS"; E = "False" },

      @{ N = "Using vSS"; E = "True" }

    }

  } $Report | Export-CSV .\Cluster-vDS-vSS_Listing.csv 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could also do something like this.

Everything in one pipeline

Get-Cluster -PipelineVariable cluster |

ForEach-Object -Process {

   Get-VMHost -Location $cluster -PipelineVariable esx |

   ForEach-Object -Process {

   Get-VirtualPortGroup -VMHost $esx |

  Select @{N='vCenter';E={([uri]$Cluster.ExtensionData.Client.ServiceUrl).Host}},

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

   @{N='VMHost';E={$esx.Name}},

   @{N='ESXi Version';E={$esx.Version}},

   @{N='Portgroup';E={$_.Name}},

   @{N='Using VSS';E={$_ -is [VMware.VimAutomation.ViCore.Types.V1.Host.Networking.VirtualPortGroup]}},

   @{N='Using VDS';E={$_ -is [VMware.VimAutomation.ViCore.Types.V1.Host.Networking.DistributedPortGroup]}}


   }

} | Export-CSV .\Cluster-vDS-vSS_Listing.csv


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

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

You could also do something like this.

Everything in one pipeline

Get-Cluster -PipelineVariable cluster |

ForEach-Object -Process {

   Get-VMHost -Location $cluster -PipelineVariable esx |

   ForEach-Object -Process {

   Get-VirtualPortGroup -VMHost $esx |

  Select @{N='vCenter';E={([uri]$Cluster.ExtensionData.Client.ServiceUrl).Host}},

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

   @{N='VMHost';E={$esx.Name}},

   @{N='ESXi Version';E={$esx.Version}},

   @{N='Portgroup';E={$_.Name}},

   @{N='Using VSS';E={$_ -is [VMware.VimAutomation.ViCore.Types.V1.Host.Networking.VirtualPortGroup]}},

   @{N='Using VDS';E={$_ -is [VMware.VimAutomation.ViCore.Types.V1.Host.Networking.DistributedPortGroup]}}


   }

} | Export-CSV .\Cluster-vDS-vSS_Listing.csv


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

0 Kudos
faherne_CTI
Enthusiast
Enthusiast
Jump to solution

Thanks Luc, worked a treat!

0 Kudos
faherne_CTI
Enthusiast
Enthusiast
Jump to solution

Is it possible to filter the clusters in the first line e.g.

Get-Cluster -Name "*EXCHANGE*"  -PipelineVariable cluster |

ForEach-Object -Process {

...

...

I keep getting errors when I add wildcard filters for clustername.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Works for me.
What kind of errors?


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

0 Kudos
faherne_CTI
Enthusiast
Enthusiast
Jump to solution

OK, I see what's going wrong now. Problems with the pipeline. I added a Foreach loop around your code to feed in vCenters and the Connect-ViServer lines are having issues.

$vcList = Import-Csv .\vC-List-EMEA.csv

$Report = foreach ($vC in $vclist){

  Connect-VIServer  $vC.fqdn -Credential $MyCredential

  Get-Cluster -Name "*EX*" -PipelineVariable cluster |

  ForEach-Object -Process {

    Get-VMHost -Location $cluster -PipelineVariable esx |

    ForEach-Object -Process {

      Get-VirtualPortGroup -VMHost $esx |

      Select @{N='vCenter';E={([uri]$Cluster.ExtensionData.Client.ServiceUrl).Host}},

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

      @{N='VMHost';E={$esx.Name}},

      @{N='ESXi Version';E={$esx.Version}},

     @{N='Portgroup';E={$_.Name}},

     @{N='Using VSS';E={$_ -is [VMware.VimAutomation.ViCore.Types.V1.Host.Networking.VirtualPortGroup]}},

     @{N='Using VDS';E={$_ -is [VMware.VimAutomation.ViCore.Types.V1.Host.Networking.DistributedPortGroup]}}

  }

}

Disconnect-VIServer *  -Confirm:$false -Force:$true

} $Report | Export-CSV .\Cluster-vDS-vSS_Listing.csv -NoTypeInformation -UseCulture

0 Kudos