This is how I clean a Windows OS prior to capture.
@echo off REM Cleanup_Mastering1.cmd is manually executed during the Windows mastering as Administrator in Audit Mode REM Disk Cleanup with all options selected cleanmgr /verylowdisk del /Q /F "C:\Windows\Temp\*.*" del /Q /F /S "%LOCALAPPDATA%\temp\*.*" del /Q /F /s "%APPDATA%\Microsoft\Windows\Recent\AutomaticDestinations\*.*" REM Delete Shadow Copies (Restore Points) vssadmin delete shadows /all /quiet REM Force chkdsk at next startup echo y | chkdsk c: /offlinescanandfix REM yes a second time del /Q /F "C:\Windows\Temp\*.*" REM Clear All Event Logs for /f %%a in ('WEVTUTIL EL') do WEVTUTIL CL "%%a" REM Restart! shutdown -r -t 0
Notice the restart.
‘cleanmgr’ will pop up with a prompt… ‘OK’ it.
If you’ve allowed your system to retrieve and apply Windows Updates (don’t!) the ‘cleanmgr’ command will take a very long time; about an hour. You’re then better off manually deleting “C:\Windows\SoftwareDistribution” before this.