This module is still a work in progress and could be destructive for production environments.
Please use at your own risk!
This PowerShell module is for freeing up disk space on Windows computers. You could use this on RDS servers, or your own local machine.
You can install the ComputerCleanup module directly from the PowerShell Gallery. More information can be found on my Blog
# One time setup
Install-Module ComputerCleanup -AllowClobber -Force
# If you get errors requesting the PSGallery and/or updating NuGet, try executing the following command before trying again:
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
# Import the module.
Import-Module ComputerCleanup -Force
# Get commands in the module
Get-Command -Module ComputerCleanup
# Get help for the module
Get-Help ComputerCleanup -Full
# Updating
Update-Module -Name ComputerCleanup
To install the module manually, or if you are using an earlier version of PowerShell that doesn't support Install-Module, simply download the module from GitHub, and copy the ComputerCleanup folder into your Modules folder.
If you're not sure where your Modules folder is, open up a PowerShell prompt and enter: $env:PSModulePath
Generally, the only function/command you'll need is Invoke-ComputerCleanup
.
I'll give two recommended parameter sets. One for running on a live/in-use environment, and one for outside of working hours.
Invoke-ComputerCleanup -Days 30 -UserTemp -SystemTemp -CleanManager -SoftwareDistribution -RecycleBin
- Runs the Windows Disk Cleanup tool.
- Removes temp files in User profiles that are older than 30 days old.
- Removes temp files in System that are older than 30 days old.
- Cleans up the "C:\Windows\SoftwareDistribution\Download" folder.
- Clears the Windows Recycle Bin
This parameter set will close running processes! Use with caution.
- You could use this as a weekly scheduled task.
Invoke-ComputerCleanup -Days 30 -UserTemp -SystemTemp -CleanManager -SoftwareDistribution -BrowserCache -TeamsCache -FontCache -RecycleBin
- Runs the Windows Disk Cleanup tool.
- Removes temp files in User profiles that are older than 30 days old.
- Removes temp files in System that are older than 30 days old.
- Cleans up the "C:\Windows\SoftwareDistribution\Download" folder.
- Clears cache for all browsers
- Clears Microsoft Teams Cache
- Clears Windows Font Cache
- Clears the Windows Recycle Bin
You'll be prompted for confirmation at the beginning, and there will be a report at the end.
Some parameters will kill multiple processes, which can be impactful in live environments. Therefore, I've added warnings for some parameters. Example:
Invoke-ComputerCleanup -Days 30 -BrowserCache -TeamsCache -UserDownloads
ℹ️ You can use the -Force
parameter to skip all confirmation prompts.
- Only remove files/folders that are older than $Days old.
- This is based on both file CreationTime AND LastWriteTime.
- This parameter does NOT apply to the following options:
-BrowserCache
-TeamsCache
-SoftwareDistribution
-FontCache
- Runs the Windows Disk Cleanup tool with the following options enabled:
- Active Setup Temp Folders
- BranchCache
- Device Driver Packages
- Downloaded Program Files
- GameNewsFiles
- GameStatisticsFiles
- GameUpdateFiles
- Memory Dump Files
- Offline Pages Files
- Old ChkDsk Files
- Previous Installations
- Service Pack Cleanup
- Setup Log Files
- System error memory dump files
- System error minidump files
- Temporary Files
- Temporary Setup Files
- Thumbnail Cache
- Update Cleanup
- Upgrade Discarded Files
- Windows Defender
- Windows ESD installation files
- Windows Error Reporting Archive Files
- Windows Error Reporting Queue Files
- Windows Error Reporting System Archive Files
- Windows Error Reporting System Queue Files
- Windows Upgrade Log Files
- Removes temp files in User profiles that are older than $Days days old. Default locations:
- USERPROFILE\AppData\Local\Microsoft\Windows\WER
- USERPROFILE\AppData\Local\Microsoft\Windows\INetCache
- USERPROFILE\AppData\Local\Microsoft\Internet Explorer\Recovery
- USERPROFILE\AppData\Local\Microsoft\Terminal Server Client\Cache
- USERPROFILE\AppData\Local\CrashDumps
- USERPROFILE\AppData\Local\Temp
- Removes temp files in system that are older than $Days days old. Default locations:
- C:\Windows\Temp
- C:\Windows\Logs\CBS
- C:\Windows\Downloaded Program Files
- C:\ProgramData\Microsoft\Windows\WER
- Cleans the "C:\Windows\SoftwareDistribution\Downloads" folder.
- Clears user font cache files located in "C:\Windows\ServiceProfiles\LocalService\AppData\Local"
- Clears browser cache files for all users.
- Browsers: Microsoft Edge, Internet Explorer, Google Chrome and Firefox.
- :warning: This will stop ALL running browser processes. Running outside of working hours is advised.
- Clears Microsoft Teams cache files for all users.
- :warning: This will stop ALL running Teams processes. Running outside of working hours is advised.
- Clears Recycle Bin.
- Invoke-ComputerCleanup
- Main controller function to invoke one or multiple cleanup functions included in this module.
- Clear-BrowserCache
- Removes browser cache files for all users.
- Browsers: Microsoft Edge, Internet Explorer, Google Chrome and Firefox.
- Clear-FontCache
- Removes user font cache files located in
C:\Windows\ServiceProfiles\LocalService\AppData\Local\
- Removes user font cache files located in
- Clear-SoftwareDistribution
- Clears the
C:\Windows\SoftwareDistribution\Downloads
folder.
- Clears the
- Clear-TeamsCache
- Removes Microsoft Teams cache files for all users.
- Invoke-CleanManager
- Runs the Windows Disk Cleanup tool with predefined options.
- Optimize-SystemFiles
- Removes common system-wide temporary files and folders older than
$Days
old. - OPTIONAL: Clears Windows Recycle Bin
- Removes common system-wide temporary files and folders older than
- Optimize-UserProfiles
- Removes common temporary files and folders older than
$Days
days old from user profiles.
- Removes common temporary files and folders older than
- Assert-RunAsAdministrator
- Verifies if script/function is running with Administrator privileges.
- Get-DiskSpace
- Gets available disk space. Used for reporting.
- Get-UserFolders
- Gets all user folders, excluding Administrators and Default/Public users
- Start-Logging
- Logging function. Very basic wrapper around
Start-Transcript
- Logging function. Very basic wrapper around