Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Disk Cleanup question

We are looking to automate some disk cleanup operations on our Windows 10 desktops using the built in Disk Cleanup utility to clean up Windows Updates files (winsxs dir) and windows.old. 

I know it can be somewhat automated using the cleanmgr commands so we first manually used :  cleanmgr /sageset:555  and set the options we wanted which threw in the appropriate registry entries .  I exported the key from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches and cleaned it up to only have the StateFlags keys

So anyways our PDQ package i created first deployed that registry key i mentioned and then next step runs:

cleanmgr /verylowdisk /sagerun:555

That all seems to work just fine however it seems to complete very quickly after the 2nd command is run even though the actual cleaning process goes on for quite a while while it does its thing.  I know its probably just reading the powershell error codes for that but curious if anyone has any ideas how to expand on this to get better completion reporting from PDQ on this type of operation? (or if theres a better way to handle it)

1

Comments

5 comments
Date Votes
  • I haven't tried this, but it looks promising: https://stackoverflow.com/a/35214197

    1
  • thanks for the link!  that does look pretty cool......i think that more or less is getting done what i already have though (setting the registry entries for the sageset and then running sagerun).  Like i said i am able to accomplish this fine through pdq but it just gives a success code right away after the sagerun command is completed instead of after the full cleanup is done so was just curious if there was any way to maybe have it continue to run until thats done but that may not be possible since that task spawns off different tasks.   either way it gets a simple way to clean stuff up! thanks for the help!

    1
  • but it just gives a success code right away after the sagerun command is completed instead of after the full cleanup is done so was just curious if there was any way to maybe have it continue to run until thats done

    I believe that's what this line does:

    Write-Host 'Waiting for CleanMgr and DismHost processes. Second wait neccesary as CleanMgr.exe spins off separate processes.'
    Get-Process -Name cleanmgr,dismhost -ErrorAction SilentlyContinue | Wait-Process
    1
  • oh ya good catch! i totally missed that part. thanks for the help here! i'll see if I can integrate that w/ this workflow.....I will say even w/out the confirmation and just running the base PS command like i originally mentioned it APPEARS to be totally silent on the user side so far which is not the case if you run it local so however PDQ is handling it is a nice benefit

    1
  • that link you sent works great!  i am testing again w/ a longer timeout period since this operation can take several hours but i think is just what we needed! thanks again

    1