Worklet: Get Hard Drive Free Space Percentage
JasonG-Automox
October 11, 2019 at 3:28 pm UTC
#Windows#Worklets
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:
powershell8 lines
If (Test-Path "$env:allusersprofile\SoftwareDistribution")
{
Exit 0
}
Else {
Exit 1
}• Under Remediation Code:
19 lines
$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"%"
}This discussion is archived and closed to replies. Continue it in the Automox Community Slack.
Discuss on Slack