Quantcast
Channel: VMware Communities : Blog List - All Communities
Viewing all articles
Browse latest Browse all 3135

Report VM's Guest disks with less than 20% free space using powercli

$
0
0

Hello,

this code permits report the vm's guest disks with less than 20% free space.

 

I would like to comment that in order to check the free space, the vmware tools must be installed and running in the virtual machines.

 

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 20) {     

    $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

 

 

(As usual, remember to use the Connect-VIServer cmdlet before!)

 

 

My powercli script is based in this two scripts:

http://www.virtu-al.net/2009/03/25/vi-toolkit-one-liner-vm-guest-disk-sizes/

vGeek: Collect disk space detail and send it in email Powercli

 

 

Best regards,

Pablo


Viewing all articles
Browse latest Browse all 3135

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>