Kaseya Community

Disk Cleanup

This question is not answered

I have been trying to automate the disk cleanup wizard.  I have created a /sageset:1 exported the registry entries and deployed them via GPO.  The issue I am running into when running the command, via any script, cleanmgr.exe /sagerun:1 the wizard pops up and "appears" to be deleting files however it is not.  I have used every string I can think of, shell commands, powershell commands, running a batch file, vbs none of them actually do anything.  The aggravating part is that I can run the commands and batch files locally on any machine and the cleanup actually works.

All Replies
  • Hey  

    Are you performing this with an agent procedure via Kaseya?

    If so, can you provide us with the agent procedure so we can take a look or possibly try to reproduce?

    If it is not a Kaseya Agent Procedure, can you please provide us with one of the scripts you are trying to use?

  • Nicolas, are you wanting me to attach xml files of the scripts?  As i don't see any way to do that.

  • Hey,  

    Yes, the XML files would be great, along with any other required files for your procedure.

    You should be able to upload using the following button when replying to the thread:

    You should be able to select a file from your computer or use a public link from a public drive, dropbox, etc.

    Let me know if you have any issues with that, if you do, you could always email me directly at nicolas.ponce@kaseya.com and I can upload it on your behalf.

  • Ok, I could upload XML files, but I have tried different strings in the scripts and have just modified the same one over and over, could I just layout what I've tried like this:

    All "StateFlags" have been deployed with GPO Preferences, so I am just trying to run CleanMgr.exe /sagerun:1

    I have tried writing my scripts several ways:

    7750.Procedure WDC Run.xml

    4101.Procedure WDC Run (1).xml

    Procedure WDC Run (2).xml

    This is the text file I save as .bat for the script that calls the batch file:DiskCleanRun.txt

    As stated, these all cause the Disk Cleanup wizard to appear and "act" like it's doing something but it never actually deletes anything.  Also, I can locally run the cleanmgr.exe /sagerun:1 from CMD and it works, or run the batch file and that works as well, but for some reason when Kaseya calls for it to be done, it just doesn't work as advertised.

    I realize that's probably a lot, thanks.

    Made links easier to see
    [edited by: rogue212005 at 12:23 PM (GMT -8) on Mar 3, 2016]
  • Hey  

    Thank you for providing this information. 

    Was this a modification of a sample procedure we provide with OOB installs?It appears as though it is and modified now.

    It may be worth a shot to try and verify what data is being removed (or is not being removed) when the sample procedure is called, or if it runs opposed to your current script:

    This has come up a number of times - with a number of different possibilities and solutions to various problems when running procedures of this fashion:





    As running cleanmgr.exe has a user dialog box appear, you  may see mixed results depending if KUsrTsk.exe is running or is not running.

    The only difference I can see is that you are using executeshellcommand vs the sample procedure which uses executefile step and calls this exe.

    I would first start by getting a support ticket in, so that you can have this documented somewhere and may get more expedited answers.

    The executeshellcommand step when run as a user, should probably use credentials or impersonate user, which may also help.

    There are several options when running cleanmgr.exe to delete:

    It sounds as though the registry flags have been set for all options to be deleted?

    If not, are specific files being deleted and others are not?

    When I ran the sample procedure, it purged the Downloaded Program Files/Temporary Internet Files from my device from the screenshot above.

    Let me know either way, more then happy to help.

  • You may find that the cleanmgr.exe does not exist on some PCs

    Here is a powershell script that will put the files where they need to be (just put this code into a *.ps1 file and have Kaseya execute it via procedure).

    If (!(Test-Path "$env:SystemRoot\System32\cleanmgr.exe")) {
    $exeLoc = Get-ChildItem -Path "$env:SystemRoot\WinSxS" -Filter "cleanmgr.exe" -Recurse | Sort-Object -Property FullName -Descending
    foreach ($exe in $exeLoc) {
    Copy-Item $exe.FullName -Destination "$env:SystemRoot\System32\cleanmgr.exe" -Force
    If (!(Test-Path "$env:SystemRoot\System32\en-US\cleanmgr.exe.mui")) {
    $muiLoc = Get-ChildItem -Path "$env:SystemRoot\WinSxS" -Filter "cleanmgr.exe.mui" -Recurse | Sort-Object -Property FullName -Descending
    foreach ($mui in $muiLoc) {
    Copy-Item $mui.FullName -Destination "$env:SystemRoot\System32\en-US\cleanmgr.exe.mui" -Force