VMware Cloud Community
krishna_v78
Enthusiast
Enthusiast
Jump to solution

DataStoreClusters inventory report along with Datacenter and Cluster details

Experts,

I'm trying to generate inventory report for Datastoreclusters along with Datacenter, Cluster, total capacity, Used space and Free space. But, not able to get the Datacenter and cluster name details in the output. Below is the script which I'm using. PowerCLI Version: 5.8 Could anyone suggest what I'm missing in the below script. I appreciate your help!!.

$dsclusreport = @()

foreach ($datacenter in Get-Content C:\temp\dcname.txt) {

   foreach ($cluster in Get-Content c:\Temp\clname.txt) {

   foreach ($datastorecluster in Get-DatastoreCluster) {

 

   $objdscluster = "" | Select DatacenterName, ClusterName, DatastoreClusterName, TotalSpaceTB, UsedSpaceTB, FreeSpaceTB, FreePercentage

   $objdscluster.DatacenterName = $datacenter.Name

   $objdscluster.ClusterName = $cluster.Name

   $objdscluster.DatastoreClusterName = $datastorecluster.Name

   $objdscluster.TotalSpaceTB = "{0:N2}" -f ($datastorecluster.CapacityGB/1024)

   $objdscluster.UsedSpaceTB = "{0:N2}" -f (($datastorecluster.CapacityGB - $datastorecluster.FreeSpaceGB) /1024)

   $objdscluster.FreeSpaceTB = "{0:N2}" -f ($datastorecluster.FreeSpaceGB /1024)

   $objdscluster.FreePercentage = "{0:p1}" -f ($datastorecluster.FreeSpaceGB / $datastorecluster.CapacityGB)

 

   $dsclusreport += $objdscluster

   #$dsclusreport += $objdscluster

     }

    }

  }

   $dsclusreport 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You're missing a couple of things:

  • You have to use the Location parameter on the Get-Cluster, to only get the clusters for a specific Datacenter
  • The Get-DatastoreCluster without any addition parameters, will get all the DatastoreClusters. You can limit by using for example the Datastore parameter

The skeleton of the script could be something like this

foreach ($datacenter in Get-Datacenter) {

    foreach ($cluster in Get-Cluster -Location $datacenter) {

        $ds = Get-Datastore -RelatedObject $cluster

        foreach ($datastorecluster in Get-DatastoreCluster -Datastore $ds) {

# The rest of the script

        }

    }

}


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

View solution in original post

0 Kudos
3 Replies
krishna_v78
Enthusiast
Enthusiast
Jump to solution

Able to get the output after changing to below code with datacenter and cluster names inputs are from a File.

$objdscluster.DatacenterName = $datacenter

   $objdscluster.ClusterName = $cluster

But, not able get the output when using Get-Datacenter and Get-Cluster.

$dsclusreport = @()

foreach ($datacenter in Get-Datacenter) {

   foreach ($cluster in Get-Cluster) {

   foreach ($datastorecluster in Get-DatastoreCluster) {

 

   $objdscluster = "" | Select DatacenterName, ClusterName, DatastoreClusterName, TotalSpaceTB, UsedSpaceTB, FreeSpaceTB, FreePercentage

   $objdscluster.DatacenterName = $datacenter.Name

   $objdscluster.ClusterName = $cluster.Name

   $objdscluster.DatastoreClusterName = $datastorecluster.Name

   $objdscluster.TotalSpaceTB = "{0:N2}" -f ($datastorecluster.CapacityGB/1024)

   $objdscluster.UsedSpaceTB = "{0:N2}" -f (($datastorecluster.CapacityGB - $datastorecluster.FreeSpaceGB) /1024)

   $objdscluster.FreeSpaceTB = "{0:N2}" -f ($datastorecluster.FreeSpaceGB /1024)

   $objdscluster.FreePercentage = "{0:p1}" -f ($datastorecluster.FreeSpaceGB / $datastorecluster.CapacityGB)

 

   $dsclusreport += $objdscluster

       }

    }

  }

   $dsclusreport 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You're missing a couple of things:

  • You have to use the Location parameter on the Get-Cluster, to only get the clusters for a specific Datacenter
  • The Get-DatastoreCluster without any addition parameters, will get all the DatastoreClusters. You can limit by using for example the Datastore parameter

The skeleton of the script could be something like this

foreach ($datacenter in Get-Datacenter) {

    foreach ($cluster in Get-Cluster -Location $datacenter) {

        $ds = Get-Datastore -RelatedObject $cluster

        foreach ($datastorecluster in Get-DatastoreCluster -Datastore $ds) {

# The rest of the script

        }

    }

}


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

0 Kudos
krishna_v78
Enthusiast
Enthusiast
Jump to solution

Awesome!! Thank you Guru. Smiley Happy

0 Kudos