VMware Cloud Community
piercj2
Enthusiast
Enthusiast

Cluster Report

Hi,

I'm trying to script a very basic report to output some info for all Clusters in a specific Datacenter

  • Cluster Name
  • Names of ESXi Hosts in the Cluster
  • Names of Datastores seen by the Cluster
  • etc...

Below is the beginnings of what i need

$report = @()

$cluster = Get-Datacenter -Name "My vDatacenter" | Get-Cluster

foreach ($c in $cluster) {

    $esx = $c | Get-VMHost

    $datastore = $esx | Get-Datastore

    $row = "" | select "Cluster Name","Host Name","Datastore Name"

    $row."Cluster Name" = $cluster.Name

    $row."Host Name" = $esx.Name

    $row."Datastore Name" = $datastore.Name

    $report += $row

}

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

Unfortunately, the output i get is the following

  

Cluster NameHost NameDatastore Name
System.Object[]System.Object[]System.Object[]
System.Object[]System.Object[]System.Object[]
System.Object[]System.Object[]System.Object[]
System.Object[]System.Object[]System.Object[]
System.Object[]System.Object[]

System.Object[]

Any help would be appreciated

Thanks

0 Kudos
1 Reply
LucD
Leadership
Leadership

Export-Csv only knows how to export scalars, not arrays.

One solution is to convert the arrays into a string.

For the Cluster you took the wrong variable

$report = @()

$cluster = Get-Datacenter -Name "My vDatacenter" | Get-Cluster

foreach ($c in $cluster) {

    $esx = $c | Get-VMHost

    $datastore = $esx | Get-Datastore

    $row = "" | select "Cluster Name","Host Name","Datastore Name"

    $row."Cluster Name" = $c.Name

    $row."Host Name" = $esx.Name -join '|'

    $row."Datastore Name" = $datastore.Name -join '|'

    $report += $row

}

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


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

0 Kudos