I’ve been looking for PowerCLI script which would help me to pull performance data for VM’s from vCenter server. I found them googling through vmware communities, source at the bottom of the page.
First script pulls from vCenter – VM performance counters and export to CSV file.
- cpu Maximum
- cpu Average
- cpu Minimum
- mem Maximum
- mem Average
- mem Minimum
add-pssnapin VMware.VimAutomation.Core Connect-VIServer -Server vcetner server IP or FQDN name $allvms = @() $vms = Get-Vm #on below entry one can specify start and finish time period by use AddHours or AddDays $stats = Get-Stat -Entity $vms -start (get-date).AddHours(-168) -Finish (Get-Date).AddHours(-159) -MaxSamples 10000 -stat "cpu.usage.average","mem.usage.average" $stats | Group-Object -Property Entity | %{ $vmstat = "" | Select VmName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin $vmstat.VmName = $_.name $cpu = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property value -Average -Maximum -Minimum $mem = $_.Group | where {$_.MetricId -eq "mem.usage.average"} | Measure-Object -Property value -Average -Maximum -Minimum $vmstat.CPUMax = [int]$cpu.Maximum $vmstat.CPUAvg = [int]$cpu.Average $vmstat.CPUMin = [int]$cpu.Minimum $vmstat.MemMax = [int]$mem.Maximum $vmstat.MemAvg = [int]$mem.Average $vmstat.MemMin = [int]$mem.Minimum $allvms += $vmstat } $allvms | Select VmName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin | Export-Csv "e:\path where csv fiule can be store" -noTypeInformation
Second script calculate guest OS disk usage and export to CSV file.
Connect-VIServer -Server <vCetner-server-IP> $MyCollection = @() $AllVMs = Get-View -ViewType VirtualMachine | Where {-not $_.Config.Template} $SortedVMs = $AllVMs | Select *, @{N="NumDisks";E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks ForEach ($VM in $SortedVMs){ $Details = New-object PSObject $Details | Add-Member -Name Name -Value $VM.name -Membertype NoteProperty $DiskNum = 0 Foreach ($disk in $VM.Guest.Disk){ $Details | Add-Member -Name "Disk$($DiskNum)path" -MemberType NoteProperty -Value $Disk.DiskPath $Details | Add-Member -Name "Disk$($DiskNum)Capacity(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.Capacity/ 1MB)) $Details | Add-Member -Name "Disk$($DiskNum)FreeSpace(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.FreeSpace / 1MB)) $DiskNum++ } $MyCollection += $Details } $MyCollection | Export-Csv "e:\artur\DISK_USAGE_01.csv" -noTypeInformation
Source: http://communities.vmware.com/community/vmtn/server/vsphere/automationtools/powercli