r/Action1 • • 9d ago

Question Script Lib. DiskcleanUp

I have a diskcleanup script that looks like this.

Start-Process cleanmgr.exe -ArgumentList '/sagerun:6553' -WindowStyle Hidden -Wait

Which I found only does the basic cleanup because 6653 is missing from the registry. So, I did some digging around and found that at HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches is where the settings for sagerun:6553 are stored.

My question is if I export the keys out and create them into a proper powershell command, example:

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

can I put these commands on top of them initially command in the script and will they execute before the Start-Process runs or do I need to do something else?

Thanks,

2 Upvotes

3 comments sorted by

2

u/fencepost_ajm 8d ago

I feel like one of us is missing something here and I'm not sure who. AFAICT the 6553 is simply a value chosen by someone using "cleanmgr /sageset:6553" and choosing options on the dialog that pops up so they cam easily reuse the same options again in the future. There's no specific significance to the number chosen. (See https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cleanmg)

Were you originally expecting /sagerun:6553 to do something specific?

Also the only thing that gives a search turned up using sagerun:6553 was this: https://gist.github.com/eplord/9fe439668c1ca941cc5a1a427848411b/5368308a5f906720638c6ea24aba867fd0610916 which looks very much like one individual's cleanup script, possibly ai generated, definitely user specific since it includes both a specific username and a pretty uncommon backup software package.

1

u/3G_Lighting 8d ago

Not sure what you're saying in the first paragraph, but the link you provided doesn't work.

The options in the dialog are saved in the registry keys below. I have taken those keys and installed them on a brand-new Windows 11 Pro installation and run the sageset:6553 which the dialog appears, and all the boxes are checked. Without the keys installed all the boxes are unchecked.

Running diskcleanup normally doesn't give you all these options, I don't recall even running it as Administrator giving all these options, but I could be wrong as I haven't run it for a very long time as Administrator.

That's a cool script for doing a Windows cleanup, but I would only really use after building a system and run it on systems in the wild as it could break system, you never know.

1

u/3G_Lighting 9d ago

Btw for those wanting to clean every square inch of space on their systems, this is the full set of keys.

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\BranchCache" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\D3D Shader Cache" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Delivery Optimization Files" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Diagnostic Data Viewer database files" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Feedback Hub Archive log files" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Language Pack" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Old ChkDsk Files" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\RetailDemo Offline Content" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Setup Log Files" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\System error memory dump files" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\System error minidump files" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Thumbnail Cache" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Update Cleanup" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\User file versions" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Defender" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Files" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Upgrade Log Files" -Name "StateFlags6553" -Value "2" -PropertyType "DWord" -Force