A One Line Command to Clear Your Primary Disk Drive
Surely there are fewer disk space issues out there, but just in case...
I know some of you have 30GB systems still in production that occasionally fill up - this may help you out. My disk cleaning script that I created a few years ago seems to be kind of used by some people. Maybe. But it occurred to me working with my team recently that even downloading the script on that legacy system you know you should get rid of but can’t quite yet may have a tough time even downloading that script, let a lone a copy of TreeSize or another cleaner.
I put together this one-liner for just that purpose. And it seems to have worked well.
IEX(Invoke-WebRequest 'https://raw.githubusercontent.com/jimrtyler/diskcleaner/refs/heads/main/DiskCleanerStandalone.ps1'); Clear-DriveJunk -DriveLetter "C" -ActuallyDeleteFiles $true -LogFile ".\diskcleaner.log"
When I showed this to a friend he remarked, “Yeah, just invoke some random PowerShell script from the Internet.”
Good point. Running a script with the combo of IEX (invoke expression) and Invoke-WebRequest of someone else’s code that you haven’t reviewed seems a bit nutty. That said, if you have actually reviewed the contents of https://raw.githubusercontent.com/jimrtyler/diskcleaner/refs/heads/main/DiskCleanerStandalone.ps1 and feel comfortably running it, this can definitely get you out of a jam.
I’ve had this script up for a minute on YouTube and someone asked what does it actually do - a great question. When I wrote the script in our pre-historic pre-AI times of autumn of 2023, I was really just trying to avoid having to download Wise Disk Cleaner, a tool that seemed to work well for me. I looked through Wise Disk’s logs and made an array of the directories it seemed to clean. I asked my PowerShell GPT what the risk of cleaning each directory actually was and here’s what it had to say:
$DriveString\WINDOWS\SoftwareDistribution\Download
Description: Stores Windows Update files that are downloaded before installation. Clearing this can free up space and force updates to redownload.
Risk: If you delete these files, Windows Updates may fail or need to redownload, potentially causing delays in applying critical updates.
$DriveString\WINDOWS\winsxs\backup
Description: Contains backup files for Windows component store. These files are used for system updates and repairs.
Risk: Deleting this may cause issues with Windows updates, repairs, or rollbacks, potentially resulting in an unstable system.
$DriveString\WINDOWS\help
Description: Stores system help files. Deleting this removes built-in help documentation.
Risk: Help files will no longer be available for offline troubleshooting, though most users rely on online resources.
$DriveString\WINDOWS\Web\Wallpaper
Description: Contains default wallpaper files used by Windows. Removing this will delete pre-installed wallpapers.
Risk: Default wallpapers will no longer be available, though this will not affect system functionality.
$DriveString\Windows\Logs\WindowsUpdate
Description: Logs related to Windows Update operations, useful for troubleshooting update issues.
Risk: Deleting these logs may make diagnosing Windows Update issues more difficult.
$DriveString\Windows\Logs\waasmediccapsule
Description: Logs related to Windows Update Medic Service, a troubleshooting component for updates.
Risk: Diagnostic information for troubleshooting update issues will be lost.
$DriveString\Windows\Logs\waasmedic
Description: Another folder containing diagnostic logs for Windows Update Medic Service.
Risk: Similar to above, these logs will no longer be available for troubleshooting.
$DriveString\Windows\Logs\SIH
Description: Logs for Software Integrity Health tasks, which ensure critical Windows components are up to date.
Risk: Deleting these may hinder troubleshooting of software integrity issues.
$DriveString\Windows\Logs\NetSetup
Description: Logs created during network setup processes.
Risk: Network troubleshooting may become more difficult without these logs.
$DriveString\Windows\Logs\MoSetup
Description: Logs related to system setup and migrations, such as during Windows upgrades.
Risk: Deleting these may cause issues in diagnosing upgrade or migration problems.
$DriveString\Windows\Logs\MeasuredBoot
Description: Logs created to validate boot integrity as part of secure boot processes.
Risk: These logs are useful for debugging secure boot or malware issues and deleting them may hinder troubleshooting.
$DriveString\Windows\Logs\DPX
Description: Deployment Platform Experience logs used during software installations.
Risk: Loss of logs may hinder troubleshooting failed software installations.
$DriveString\Windows\Logs\DISM
Description: Logs for the Deployment Image Servicing and Management tool, used to manage Windows images.
Risk: Without these logs, diagnosing DISM-related issues becomes harder.
$DriveString\Windows\Logs\CBS
Description: Component-Based Servicing logs. These track operations performed by the Windows servicing stack.
Risk: Clearing these logs may complicate diagnosing servicing stack-related issues or failed updates.
$DriveString\Windows\Logs\StorGroupPolicy.log
Description: Logs related to storage group policy configurations.
Risk: Troubleshooting storage policy misconfigurations may become more difficult.
$DriveString\Windows\System32\CatRoot2\dberr.txt
Description: Database error logs related to Windows cryptographic services.
Risk: Issues with cryptographic services may become harder to diagnose.
$DriveString\Windows\debug
Description: Contains debug logs, typically used for troubleshooting system errors.
Risk: Deleting this folder can make diagnosing system errors more challenging.
$DriveString\Windows\security\logs\scecomp.old
Description: Old log files from the Security Configuration Editor component.
Risk: Removing these logs will not affect current operations but may prevent historical analysis.
$DriveString\Windows\security\logs\scecomp.log
Description: Current log files from the Security Configuration Editor component.
Risk: Removing these logs may hinder troubleshooting security policy issues.
$DriveString\Windows\SysWOW64\Gms.log
Description: Logs related to 32-bit software components running on 64-bit Windows.
Risk: Deleting these logs may make troubleshooting 32-bit application issues harder.
$DriveString\Windows\SharedPCSetup.log
Description: Logs created during shared PC setup processes.
Risk: Without these logs, diagnosing shared PC setup issues may become difficult.
$DriveString\Windows\stuperr.log
Description: Error logs for startup-related processes.
Risk: Startup troubleshooting will be more difficult without these logs.
$DriveString\Windows\setupact.log
Description: Logs created during the setup process, including system installations or upgrades.
Risk: Removing these logs may make it harder to troubleshoot installation issues.
$DriveString\Windows\PFRO.log
Description: Pending file rename operations log, used during file or application updates.
Risk: Deleting this file may disrupt pending operations or updates.
$env:LOCALAPPDATA\Microsoft\Windows\Explorer\thumbcache_*
Description: Stores thumbnail cache files for Windows Explorer. Clearing this removes thumbnail previews.
Risk: Windows will regenerate thumbnails, which may temporarily slow down file browsing.
$env:LOCALAPPDATA\Microsoft\Terminal Server Client\Cache
Description: Stores Remote Desktop Protocol (RDP) client cache files.
Risk: Deleting these files may slow down RDP performance temporarily as cache is rebuilt.
$DriveString\Windows\system32\FNTCACHE.DAT
Description: Font cache file used to speed up font rendering.
Risk: Clearing this may slow down text rendering until the cache is rebuilt.
$DriveString\Windows\Temp
Description: Temporary files directory for the Windows operating system.
Risk: Removing files in use could cause applications to crash or lose data. Use caution.
$env:LOCALAPPDATA\Temp
Description: Temporary files specific to the current user.
Risk: Deleting files in use could disrupt currently running applications.
$env:LOCALAPPDATA\Microsoft\Edge\User Data
Description: Stores user data, such as profiles and settings, for Microsoft Edge browser.
Risk: Deleting this may cause loss of browser settings, bookmarks, or user data.
$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache
Description: Cache directory for the default user profile in Google Chrome.
Risk: Clearing this may slow down the browser temporarily until the cache is rebuilt.
Thanks for scrolling past all of those back to the post! Though there are identified risks, I have done this on numerous systems in the past. Additionally, the script empties the recycle bin.
While it is useful, it was written with my non-AI driven faculties as I noted earlier. I am planning a video where I go over a GPT driven cleanup of the script to add some additional error handling/suppression, as well as disk size calculations.
I hope you all find this one useful!
-Jim