Search This Blog

Tuesday, November 23, 2010

PowerCLI Gets Resource Limits of VM.

Here is a PowerCLI script for getting VM resources. Get-View is used because it is many times faster than using Get-VM. Post comments if you have questions or improvements.

param ($ShowAll)

write-host "#Gets Resource Limits of VM's. –Showall Parameter can be used to remove filter."

$vmset = Get-view -ViewType VirtualMachine

if ($ShowAll ){ Write-Host "#Show all VM's"

}else{ #filter

write-host "#Use ""-ShowAll True "" to show all VM's"

$vmset = $vmset | where { ($_.Config.MemoryAllocation.Limit -gt 0) -OR $_.Config.CpuAllocation.Limit -gt 0 }

}

$table = @()

$vmset | % { if ($i -gt 0 ) {$i = 0}else{$i=$i+1}

$_ | % {

$row = "" | select Name, MemoryLimit, CpuLimit, MemoryMB, MemoryReservation, CpuReservation

$row.Name = $_.Name

$row.MemoryMB = $_.Summary.Config.MemorySizeMB

$row.MemoryReservation = $_.Config.memoryallocation.reservation

$row.MemoryLimit = $_.Config.memoryallocation.limit

$row.CpuReservation = $_.Config.CpuAllocation.reservation

$row.CpuLimit = $_.Config.CpuAllocation.limit

$table += $row

$i = $i + 1

}

}

$table

Output looks like this:

No comments:

Post a Comment