Automox Worklet: Run Windows Cleanup Tool

This worklet will allow you to run the Windows Cleanup Tool on any of your Windows endpoints, based on the amount of free space remaining on the C: drive.

Before you run this Worklet

If you use the /SageSet and /SageRun commands, you’ll need to create presets on the endpoints first. This /SageSet process can be automated, as some folks have demonstrated here

If you don’t want to bother with the /SageSet presets, you can use the /VeryLowDisk flag instead, with the caveat that this will pop up the scan completion windows on the endpoint, which might be confusing to users. More documentation on the cleanmgr.exe flag here.

Automox Worklet: Run Windows Cleanup Tool

To deploy this endpoint hardening Worklet, do the following:

  1. Log in to your Automox Console.
  2. Navigate to the System Management page and click Create Policy in the upper right-hand section of the screen.
  3. Choose Windows under Worklet.
    Screen Shot 2019-10-14 at 4.09.21 PM
  4. Copy and paste the Evaluation and Remediation code scripts from below. Choose the remediation code that matches your OS version.

Evaluation:

# Replace $MinDiskFree with whatever value you want as the minimum available space before running the cleanuptool
# The $MinDiskFree value is in bytes
# Only checks the C drive for space
$Diskfree = (Get-WmiObject -Class Win32_logicaldisk - Filter "DeviceID = 'C:'").freespace
$MinDiskFree = '5000000000'
 
if ($DiskFree < $MinDiskFree) {
    Exit 0
} else { Exit 1 }

Remediation:

# Assumes you've already setup a preset using the /SageSet flag, in the 1 preset.  If you use a different preset slot, then adjust accordingly.
# The /SageSet slots are available from 1 to 65535
# To set a preset, run the following command on your Windows endpoint: cleanmgr.exe /SageSet:1, and then select which options you want for cleanup
# After this is done, the following command will run with those presets and will not surface a message to the end user
Try {
        cleanmgr.exe /Sagerun:1
    Write-Output "Disk cleanup finished"
    Exit 0
} catch {
    Write-Output "Disk cleanup failed"
    Exit 1
}
 

5. Select Create Worklet.

6. Assign the Worklet to a group or multiple groups and select Save Changes. 

7. Execute the Worklet by selecting the Execute Policy Now button. 

If you need technical assistance, contact our support team at support@automox.com.

About Automox

Facing growing threats and a rapidly expanding attack surface, understaffed and alert-fatigued organizations need more efficient ways to eliminate their exposure to vulnerabilities. Automox is a modern cyber hygiene platform that closes the aperture of attack by more than 80% with just half the effort of traditional solutions.

Cloud-native and globally available, Automox enforces OS & third-party patch management, security configurations, and custom scripting across Windows, Mac, and Linux from a single intuitive console. IT and SecOps can quickly gain control and share visibility of on-prem, remote and virtual endpoints without the need to deploy costly infrastructure. 

Experience modern, cloud-native patch management today with a 15-day free trial of Automox and start recapturing more than half the time you're currently spending on managing your attack surface. Automox dramatically reduces corporate risk while raising operational efficiency to deliver best-in-class security outcomes, faster and with fewer resources.

Get Instant Updates on Vulnerabilities

Subscribe to receive Automox vulnerability alerts

Reduce your threat surface by up to 80%

Make all of your corporate infrastructure more resilient by automating the basics of cyber hygiene.

Take 15 days to raise your security confidence!
Start a Free Trial