0

How can I delete/cleanup all the folders under "Clean System Files" option in disk cleanup via powershell? The code below wasn't able to achieve what I wanted to.

(Start-Process -FilePath "$env:systemroot\system32\cleanmgr.exe" -ArgumentList "/sagerun:1" -Wait -PassThru)

Thank you,

IamBayMax
  • 51
  • 9
  • did you check this link: https://stackoverflow.com/questions/28852786/automate-process-of-disk-cleanup-cleanmgr-exe-without-user-intervention – Mahmoud Moawad Jan 07 '22 at 12:37

2 Answers2

1

Have you tried the autoclean option?

cleanmgr.exe /AUTOCLEAN

It will clean below folders: C:$Windows.~BT* C:$Windows.~LS* C:$Windows.~WS* C:\ESD\Download* C:\ESD\Windows* C:$WINDOWS.~Q* C:$INPLACE.~TR* C:\Windows.old* C:\Windows\Panther

It will also write 2 log files as following:

C:\Windows\System32\LogFiles\setupcln\setupact.log C:\Windows\System32\LogFiles\setupcln\setuperr.log

PSBeginner
  • 21
  • 3
0

you can delete them one by one by starting the cmd in admin mode. below is an example to delete the $windows.~BT folder

takeown /F C:\$Windows.~BT\* /R /A 
icacls C:\$Windows.~BT\*.* /T /grant administrators:F 
rmdir /S /Q C:\$Windows.~BT\
raja emani
  • 151
  • 1
  • 4