Found on internet – PowerCLI scripts

Shares

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

0 0 votes
Article Rating

Artur Krzywdzinski

Artur is Consulting Architect at Nutanix. He has been using, designing and deploying VMware based solutions since 2005 and Microsoft since 2012. He specialize in designing and implementing private and hybrid cloud solution based on VMware and Microsoft software stacks, datacenter migrations and transformation, disaster avoidance. Artur holds VMware Certified Design Expert certification (VCDX #077).

You may also like...

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x

FOR FREE. Download Nutanix port diagrams

Join our mailing list to receive an email with instructions on how to download 19 port diagrams in MS Visio format.

NOTE: if you do not get an email within 1h, check your SPAM filters

You have Successfully Subscribed!

Pin It on Pinterest