Worklet: Get Hard Drive Free Space Percentage

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"%"
    }
1 Like

HI WEBBY

2 Likes