Powershell – VMware ESX Auditing

auditpowershellvmware-esx

I'm looking to generate an excel spreadsheet with various information about each one of my company's ~140 VMs residing on 7 ESX 3.5 servers – specifically, the VM's:

  • Name
  • Allocated Memory, Processors, Hard Drive
  • Average Memory, Processor utilization for a given time period
  • Maximum Memory, Processor utilization for a given time period

I know I can manually fill in a spread sheet, but I'm looking for a script (perhaps powershell) that I can run on a scheduled basis to keep an eye on things.

Thanks!

Best Answer

If you want a really comprehensive solution, check out the VI Power Documenter. It may be overkill for you though.

Here is a PowerShell script which will grab most of the info you were looking for and export to a CSV which you can easily work with in Excel of course.

param ( $Path )
Connect-VIServer -Server MyVIServer
$HDPrimarySize = @{
    Name = "Primary HD Size (GB)"
    Expression = { $_.HardDisks[0].CapacityKB / 1MB }
}
$AvgMemUsage = @{
    Name = "Mem Usage (Daily Avg %)"
    Expression = { ($_ | Get-Stat -Stat mem.usage.average -MaxSamples 1 -ErrorAction SilentlyContinue ).Value }
}
$vm = Get-VM
$output = $vm | Select-Object Name, MemoryMB, NumCpu, $HDPrimarySize, $AvgMemUsage 
$output | Export-Csv -NoTypeInformation -Path $Path