none
Cleanmgr for SCCM client not for Update Cleanup RRS feed

  • Question

  • Have you tried using the cleanmgr in a SCCM package for clients?

    Why is there a difference when this is run by the user from Software Center and when this is run as administrator by me in the same computer ?

    Here is my script :

    #Requires -RunAsAdministrator
    
    $SageSet = "StateFlags0010"
    $Base = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\"
    
    $Locations= @(
        "Active Setup Temp Folders"
        "BranchCache"
        "D3D Shader Cache"
        "Delivery Optimization Files"
        "Diagnostic Data Viewer database files"
        "Downloaded Program Files"
        "Feedback Hub Archive log files"
        "GameNewsFiles"
        "GameStatisticsFiles"
        "GameUpdateFiles"
        "Internet Cache Files"
        "Language Pack"
        "Memory Dump Files"
        "Offline Pages Files"
        "Old ChkDsk Files"
        "Previous Installations"
        "Recycle Bin"
        "RetailDemo Offline Content"
        "Service Pack Cleanup"
        "Setup Log Files"
        "System error memory dump files"
        "System error minidump files"
        "Temporary Files"
        "Temporary Setup Files"
        "Temporary Sync Files"
        "Thumbnail Cache"
        "Update Cleanup"
        "Upgrade Discarded Files"
        "User file versions"
        "Windows Defender"
        "Windows Error Reporting Archive Files"
        "Windows Error Reporting Files"
        "Windows Error Reporting Queue Files"
        "Windows Error Reporting System Archive Files"
        "Windows Error Reporting System Queue Files"
        "Windows ESD installation files"
        "Windows Upgrade Log Files"
    
    )
    # Create the Stateflags
    
    ForEach($Location in $Locations) {
        
        $MyTestPath = Test-Path ($base+$Location)
        if($MyTestPath) {
       
            Set-ItemProperty -Path $($Base+$Location) -Name $SageSet -Type DWORD -Value 2
            # Write-host $Location -ForegroundColor Green 
        }else {
            # Write-host $Location -ForegroundColor Magenta
        }
    }
    
    # Do the cleanup . have to convert the SageSet number
    $Args = "/sagerun:$([string]([int]$SageSet.Substring($SageSet.Length-4)))"
    Start-Process -Wait "$env:SystemRoot\System32\cleanmgr.exe" -ArgumentList $Args -WindowStyle Normal
    
    # Remove the Stateflags
    $n_true = 0
    $n_false = 0
    ForEach($Location in $Locations)
    {
        $MyTestPath = Test-Path ($base+$Location)
        if($MyTestPath) {
       
            Remove-ItemProperty -Path $($Base+$Location) -Name $SageSet -Force # 
            Write-host $Location -ForegroundColor Green
            $n_true = $n_true + 1
        }else {
            Write-host $Location -ForegroundColor Magenta
            $n_false = $n_false + 1 
        }
    }
    
    Write-host "number of cleanup action done : $n_true"  -ForegroundColor Green 
    Write-host "number of cleanup action skiped : $n_false"  -ForegroundColor Magenta
    
    
    Start-Sleep -Seconds 10
    

    As you can see 1st print screen Update Cleanup was skiped

    and manual run as admin not

    Where is the problem ?



    • Edited by Michels1234 Monday, November 16, 2020 10:42 AM
    Monday, November 16, 2020 9:11 AM

Answers