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:

Thursday, November 4, 2010

Powercli one liner for finding Fault Tolerance Detection

Here's the fancy script  using the last the last article's oneliner:

#create array for table
$table = @()

#get-view of VM's and filter on FaultToleranceState
$ft = Get-View -ViewType VirtualMachine -filter @{"Runtime.FaultToleranceState"="enabled|ing"  }

#post message
write-host "Found FT on "  ($ft.count/2) "VM(s)..."

#assign results array
$ft | % {    
    $row = "" | select Name, FaultToleranceState, RecordReplayState
    $row.Name = $_.Name
    $row.FaultToleranceState = $_.Runtime.FaultToleranceState
    $row.RecordReplayState = $_.Runtime.RecordReplayState
    $row.RecordReplayState = $_.Runtime.RecordReplayState
    $table +=  $row
}
write-host ($ft.count )  "FT instances found."
$table


Output:


[vSphere PowerCLI] C:\powercli> .\Get-FT.ps1

 Found FT on  2 VM(s)...

 

Name                 FaultToleranceState         RecordReplayState

----                 -------------------         -----------------

testvm2              running                     recording 

testvm2              running                     replaying

 

keywords: Vmware vSphere powershell 2 powercli FT

VMware Powercli oneliner for finding FaultTolerance (FT) Virtual Machines


Get-View -ViewType VirtualMachine -filter @{"Runtime.FaultToleranceState"="enabled|ing"  }

Using Get-View is a very fast method. Took a while to figure out the filter aspect. This link is where I got my info:
http://wannemacher.us/?p=259