PowerCLI - Show all VMs with VM Disks less than % (requires vmtools)

This handy script will report all VMs with VM Disks less than the specified percentage...

Requires: VMware, Powershell and PowerCLI

Code (set to 15% by default):

ForEach ($VM in Get-VM | where-object {($_.powerstate -ne "PoweredOff") -and ($_.Extensiondata.Guest.ToolsStatus -Match ".*Ok.*")}){

ForEach ($Drive in $VM.Extensiondata.Guest.Disk) {

$Path = $Drive.DiskPath

#Calculations
$Freespace = [math]::Round($Drive.FreeSpace / 1MB)
$Capacity = [math]::Round($Drive.Capacity/ 1MB)

$SpaceOverview = "$Freespace" + "/" + "$capacity"
$PercentFree = [math]::Round(($FreeSpace)/ ($Capacity) * 100)

#VMs with less space
if ($PercentFree -lt 15) {
$Output = $Output + "Vm: " + $VM.Name + "`n"
$Output = $Output + "Disk: " + $Path + "`n"
$OutPut = $Output + "Free(MB): " + $Freespace + "`n"
$Output = $Output + "Free(%): " + $PercentFree + "`n"
}

} # End ForEach ($Drive in in $VM.Extensiondata.Guest.Disk)

} # End ForEach ($VM in Get-VM)

$Output

  • powercli, vmware, powershell
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

PowerCLI - datastore capacity with free space percentage (one liner)

This is a one liner that will compute free space percentage as well as dump datastore name,...

PowerCLI - Get IP of VM

Another simple one liner to find a VM by IP (sometimes this times out in the GUI)Requires:...

Powered by WHMCompleteSolution