AutomoxAutomox

Check disk space on C: drive

Stambo-Automox
August 26, 2021 at 9:38 pm UTC

Automox requires a minimum of 3GB of free disk space in order to execute daily functions prioperly. This worklet checks for free disk space on the C:\ drive.

The worklet will produce a result in the Activity Log only if a host has less than 3.0GB of free space on the C:\ drive.

Evaluation:

powershell15 lines
$runCheck = {

$minDiskSpaceGB = 3.0
$diskCheck = Get-WmiObject -Class Win32_logicaldisk -Filter "DriveType = '3'" | Where-Object {$_.DeviceID -eq "C:"}| Select-Object -Property DeviceID, @{L='FreeSpaceGB';E={"{0:N2}" -f ($_.FreeSpace /1GB)}},@{L="Capacity";E={"{0:N2}" -f ($_.Size/1GB)}} | Where-Object {[float]$_.FreeSpaceGB -lt $minDiskSpaceGB}

if ( $diskCheck -eq $null ) 
{ 
    return 0
}
else {
    return 1
} 
}

exit $exitCode = & $runCheck

Remediation:

powershell15 lines
trap {  $host.ui.WriteErrorLine($_.Exception); exit 90 }

$runCheck = {

$minDiskSpaceGB = 3.0
$diskCheck = Get-WmiObject -Class Win32_logicaldisk -Filter "DriveType = '3'" | Where-Object {$_.DeviceID -eq "C:"}| Select-Object -Property DeviceID, @{L='FreeSpaceGB';E={"{0:N2}" -f ($_.FreeSpace /1GB)}},@{L="Capacity";E={"{0:N2}" -f ($_.Size/1GB)}} | Where-Object {[float]$_.FreeSpaceGB -lt $minDiskSpaceGB}

return $diskCheck.FreeSpaceGB
}

Write-Output "AX Compatibility Failure: insufficient disk space on host $gc $env:computername"
Write-Output "Free space:"

Invoke-Command $runCheck
Write-Output "GB"

This discussion is archived and closed to replies. Continue it in the Automox Community Slack.

Discuss on Slack

Replies (5)

cgreggoAugust 27, 2021
#1

The response from the servers API endpoint also includes free space information in detail.VOLUME. Filter the volumes to where IS_SYSTEM_DISK=true and VIOLA! Very handy for anticipating problems for upcoming scheduled patching events.

Retrieve details for all devices - Automox API Reference Guide

Stambo-AutomoxAugust 27, 2021
#2

Yes, indeed very useful via API call cgreggo – thanks for pointing that out! Two ways to accomplish the goal here: one API-centric an the other UI-centric.

cgreggoAugust 30, 2021
#3

Yes, very much appreciate the flexibility to ask the questions in both UI and API. Thanks!

Tina.PerrySeptember 8, 2021
#4

Is it possible for Automox to email alerts or for the alerts to show on the dash board when you first login rather than having to hunt for the alerts?

Stambo-AutomoxSeptember 8, 2021
#5

Hi Tina,

The alerts cannot currently display on a dashboard, but you could definitely configure the Remediation part of the script to email you each time a specific host fails the free space check.

Here is a generic PowerShell example of sending an email:

Send-MailMessage -From 'User01 <user01@fabrikam.com>' -To 'User02 <user02@fabrikam.com>', 'User03 <user03@fabrikam.com>' -Subject 'Free Disk Space Issue:' -Body "Low disk space on host X" -SmtpServer 'smtp.yourmailserver.com'

Of course you would want to modify this to meet your specific recipients, your SMTP server, the message body, etc.