VMware Cloud Community
peter79
Enthusiast
Enthusiast
Jump to solution

Need script to find disks and datastores that are near capacity.

Guys,

I'm faitly new to Powershell, is it possible to write a script tht will find any virtual disks and datastores that are are over 90% full?  I would also like to export the results to an excel file.

Thanks.

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

For a 90% threshold you leave the value on 0.1.

I calculate the free space as a percentage, so if the freespace is less than or equal to 0.1 there is 10% or less free space available.

Hope that makes sense.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
4 Replies
EXPRESS
Enthusiast
Enthusiast
Jump to solution

Try this http://www.robware.net/ RVTools. I have been using it, it works good.

Thank you, Express
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try the following.

Note that the guests need to have the VMware Tools to be able to provide the info.

# Datastores 
$dsThreshold
= 0.1 Get-Datastore | where {$_.FreeSpaceMB/$_.CapacityMB -lt $dsThreshold} | `
    Select Name,@{N="Free";E={"{0:p1}" -f ($_.FreeSpaceMB/$_.CapacityMB)}} # Guest disks
$hdThreshold
=  0.1 foreach($vm in (Get-VM | where{$_.Guest.State -eq "running"} | Get-VMGuest)){     $vm.Disks | where {$_.FreeSpace/$_.Capacity -le $hdThreshold} | `
        Select @{N="VM";E={$vm.VmName}},Path,@{N="Free";E={"{0:p1}"-f ($_.FreeSpace/$_.Capacity)}} }


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
peter79
Enthusiast
Enthusiast
Jump to solution

LucD,

Thanks for the quick response.  Is the variable dsThreshold where I specify my threshold?  If I'm looking for any datastores above 90% capacity do I set

$dsThreshold = 90 (or would it be .9).

Sorry for all the stupid questions I'm new to powershell.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

For a 90% threshold you leave the value on 0.1.

I calculate the free space as a percentage, so if the freespace is less than or equal to 0.1 there is 10% or less free space available.

Hope that makes sense.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos