This is also where i strugled when i first started, the key is to create your own object and add each item you want to the object so in the case o the first part of your script below:
Clustername
Total CPU Resources ($test = get-cluster <clustername> | get-view)($test.summary.totalcpu)
Total Memory ($test = get-cluster <clustername> | get-view)($test.summary.totalmemory)
Number of Hosts ($test = get-cluster <clustername> | get-view)($test.summary.NumHosts)
Total Processors ($test = get-cluster <clustername> | get-view)($test.summary.numcpucores)
Number of Virtual Machines (?)
We can do this by first retrieving the cluster object and storing it in a variable, this makes all the repeat calls come from this variable rather than calling the information from the virtual infrastructure each time:
$clusters = Get-Cluster | Get-View
Then we can use this to get our other objects and add them to our uberobject, in the case below i have called this 'uberobject'
$Clusters = Get-Cluster | Get-View
$UberObject = @()
Foreach ($Cluster in $Clusters){
$Details = "" | Select Name, TotalCPUResource, TotalMemory, NumberofHosts, TotalProcessors, NumberofVMs
$Details.Name = $Cluster.Name
$Details.TotalCPUResource = $Cluster.summary.totalcpu
$Details.TotalMemory = $Cluster.summary.totalmemory
$Details.NumberofHosts = $Cluster.summary.NumHosts
$Details.TotalProcessors = $Cluster.summary.numcpucores
$Details.NumberofVMs = (Get-Cluster $Cluster.Name | Get-VM).Count
$UberObject += $Details
}
$UberObject
Now we can build up our uberobject with each section and then finally export it to csv or html or whatever.
I will leave the rest for you to add :smileywink:
Hope this helps !
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
http://virtu-al.net