What we have today, was brought up on #ESX on EfNet. They were looking for a script to generate output similar to what you get by clicking on “Hosts and Clusters”, selecting “File > Export > Export List…”
Like this:
What I came up with is not quite as pretty, but, it works, and you can schedule it using the Windows Task Scheduler. First the code:
   1:  Begin {
   2:      $hostCount= @{
3: Name = "hostCount"
4: Expression = { $_ | get-vmhost | measure-object | %{$_.Count} }
   5:      }
   6:      $vmCount = @{
7: Name = "vmCount"
8: Expression = { $_ | get-vm | measure-object | %{$_.Count} }
   9:      }
  10:  }
  11:   
  12:  Process {
  13:      $InputTypeName = $_.GetType().Name
14: if ( $InputTypeName -eq "DatacenterImpl" ) {
  15:          $output = $_ | select Name, $hostCount, $vmCount
16: return $output
  17:      }
  18:  }
I’ve saved this in a file creatively called export-list.ps1. It requires you to be connected to a vCenter server, and accepts a datacenter object ($InputTypeName –eq “DatacenterImpl”) from the pipeline. From there it takes each, and spits them out, like this:
[VI Toolkit] C:\> get-datacenter | .\scripts\export-list.ps1
Name                                        hostCount                   vmCount
    
—-                                        ———                   ——-
dev 1 3
stage 1 5
prod 1 8
Sexy, right? Not so much, but this is where PowerShell and the VI Toolkit shine, in their flexibility. So you want HTML? Check this out:
[VI Toolkit] C:\> get-datacenter | .\scripts\export-list.ps1 | ConvertTo-HTML > report.html
Just open report.html, and run with it. Scheduling this in Task manager isn’t that much harder, but will remain a task for the reader.
 
									

Your blog is very interesting. I would like to tell that I have been looking for such information and finally got it. Thanks a lot.
regards
charcoal grill