Advertisement
aveyo

windows_update_cleanup

Mar 22nd, 2022 (edited)
2,808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.55 KB | None | 0 0
  1. @(set "0=%~f0"^)#) & powershell -nop -c iex([io.file]::ReadAllText($env:0)) & exit /b
  2. $_Paste_in_Powershell = {
  3. $host.ui.rawui.windowtitle = 'WINDOWS UPDATE CLEANUP' # v2023.07.13
  4. write-host "ResetBase removes superseded components (quicker, but might break 'Reset this PC' feature)" -fore Gray
  5. write-host "Press [Y] to ResetBase, [N] to just cleanup components - selected in 10s:" -fore Green -nonew
  6. choice /n /t 10 /d N /m " "; $resetbase=$lastexitcode -ge 2; kill -name 'dism.exe','cleanmgr.exe' -force -ea 0  
  7. if ($resetbase) {Dism /Online /Cleanup-Image /StartComponentCleanup /ResetBase}
  8. else {Dism /Online /Cleanup-Image /StartComponentCleanup}
  9. write-host "`nPlease wait while running Update Disk Cleanup. If it takes too long, Ctrl+C and relaunch" -fore Gray
  10. $clean = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches'
  11. $items = 'Update Cleanup','Temporary Setup Files','ServicePack Cleanup', # 'BranchCache','Delivery Optimization Files',
  12.          'System error memory dump files','System error minidump files','Windows Error Reporting Files','Windows Defender'
  13. foreach ($i in $(reg query "$clean")) {reg add "$i" /f /v StateFlags2022 /d 0 /t reg_dword >$null 2>&1}
  14. foreach ($i in $items) {reg add "$clean\$i" /f /v StateFlags2022 /d 2 /t reg_dword >$null}
  15. cleanmgr /sagerun:2022; while (get-process cleanmgr -ea 0) {sleep -m 1000}
  16. Dism /Online /Get-packages /Format:table
  17. Dism /Online /Cleanup-Image /AnalyzeComponentStore
  18. } ; start -verb runas powershell -args "-nop -noe -c & {`n`n$($_Paste_in_Powershell -replace '"','\"')}"
  19. $_Press_Enter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement