

This program will help remove unnecessary files from your computers, such as temporary internet files and older versions of programs. The Disk Cleanup button can be found in the Backup and Restore section in the Control Panel. One of the steps is to perform a Disk Cleanup. When starting a new installation of Windows, many things need to be done before installing anything. When you’re done selecting items, click OK at the bottom of the window to delete them from your computer’s hard drive. You can select items individually or click Select All on the top left side of the window. Then click the Disk Cleanup button in the window’s System section.ĭisk Cleanup will scan your hard drive for temporary files and show them in a list with a checkbox next to each item. It might free up a small amount of space don’t expect miracles.To open Disk Cleanup, right-click the Computer icon on your desktop and select Properties. Now, whether it does much good during the image creation process is a separate debate. I added the 15-minute (900 second) timeout because when I ran the script to test it on my server, the processes never ended, so it’s good to give up at some point. The script enables every cleanup item possible (line #1), starts CLEANMGR.EXE (line #2), then waits for separate CLEANMGR.EXE and DISMHOST.EXE processes to complete before exiting. (This is a three-line script, so if you copy it, make sure the first line doesn’t have a break in it.) To run that script from MDT, copy the script into your deployment share’s “Scripts” folder and set up a “Run PowerShell script” step: Get-Process -Name cleanmgr,dismhost -ErrorAction Silentl圜ontinue | Wait-Process -Timeout 900


Start-Process -FilePath CleanMgr.exe -ArgumentList ‘/sagerun:1’ -WindowStyle Hidden -Wait

Get-ChildItem -Path ‘HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches’ | New-ItemProperty -Name StateFlags001 -Value 2 -PropertyType DWORD Combine that documentation with some sample PowerShell scripts on StackOverflow and you can see where my script was derived, I just simplified it a little: The bulk of the work for this was amazingly already documented by Microsoft. Since I wanted to put this into an MDT task sequence, I also wanted to wait until the process was done. It turns out that the process is fairly simple: Set registry values to say what you want to clean up and then launch CLEANMGR.EXE with the right command line options. I’ve seen a variety of blogs over the years that talk about how to do this, but I never took the time to actually try it myself.
