Getting Virtual Machine CPU, Disk and Memory

I was asked to pull disk, memory and cpu statistics from VMware guests managed by multiple Virtual Center servers. Working with the VMWare Senior Administrator, we came up with this.


$CsvFile = "C:\VM_Hosts_Info.csv"
$CsvData = @()
$VCSrvs = "VCenter01","VCenter02","VCenter03"
ForEach ($VCSrv in $VCSrvs){
Connect-VIServer -server $VCSrv
Get-VM | % {
$VM = $_
$Disk_T = "{0:N1}" -f(($VM | Get-HardDisk | measure-object -property CapacityKB -sum).Sum/1mb)
$Row = "" | Select Name,Environment,MemoryMB,NumCPU,Total_DiskGB
$Row.Name = $VM.Name
$Row.Environment = $VCSrv
$Row.MemoryMb = $VM.MemoryMb
$Row.NumCpu = $VM.NumCpu
$Row.Total_DiskGB = $Disk_T
$CsvData += $Row
}}
$CsvData | Export-Csv $CsvFile -noTypeInformation

Hope this helps.

All information is provided on an AS-IS basis, with no warranties and confers no rights.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s