Skip to main content

Worklet: Get Hard Drive Free Space Percentage

  • October 11, 2019
  • 2 replies
  • 206 views

JasonG-Automox

Checks the percentage of free space on all drives. Only run manually. The evaluation code will always return true. The output will be in your activity log. Edit the variable $SpaceAlert to equal the percentage to report on. If the percentage free is greater then this number nothing will happen. If its lower it will echo to your activity log.
• Under Evaluation Code:

If (Test-Path "$env:allusersprofile\SoftwareDistribution")
{
Exit 0

}
Else {
Exit 1
}

• Under Remediation Code:

$SpaceAlert = '10'
$disks = get-wmiobject -class "Win32_LogicalDisk" -namespace "root\CIMV2"

$results = foreach ($disk in $disks)
{
    if ($disk.Size -gt 0)
    {
        $size = [math]::round($disk.Size/1GB, 0)
        $free = [math]::round($disk.FreeSpace/1GB, 0)
        $freespace = ($free/$size) * 100
        $freespace = [math]::Round($freespace)
    }
}
If ($freespace >$SpaceAlert) {
Exit 0
}
Else {
    Write-Output "Free space " $freespace"%"
    }

2 replies

dimforest
Forum|alt.badge.img
  • Power User
  • 169 replies
  • October 17, 2019

HI WEBBY


  • Rookie
  • 1 reply
  • June 7, 2022

The foundation to checking drive space is awesome!
I may be missing something relatively easy, but this isn’t reporting all my systems drives.
Any ideas?


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings