you could get a list of the available VolumeCaches and set to all a Stateflag with:
# Create reg keys
$StateFlags= "Stateflags0099"
$VolCaches = gci "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches"
foreach($VC in $VolCaches)
{
New-ItemProperty -Path "$($VC.PSPath)" -Name $StateFlags -Value 2 -Type DWORD -Force | Out-Null
}
But you have no control which to include in the cleanup. With this script you may edit (shorten) the list individually.
#Requires -RunAsAdministrator
$SageSet = "StateFlags0099"
$Base = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\"
$Locations= @(
"Active Setup Temp Folders"
"BranchCache"
"Downloaded Program Files"
"GameNewsFiles"
"GameStatisticsFiles"
"GameUpdateFiles"
"Internet Cache Files"
"Memory Dump Files"
"Offline Pages Files"
"Old ChkDsk Files"
"Previous Installations"
"Recycle Bin"
"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 Queue Files"
"Windows Error Reporting System Archive Files"
"Windows Error Reporting System Queue Files"
"Windows ESD installation files"
"Windows Upgrade Log Files"
)
ForEach($Location in $Locations) {
Set-ItemProperty -Path $($Base+$Location) -Name $SageSet -Type DWORD -Value 2 -ea silentlycontinue | Out-Null
}
# 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 Hidden
# Removw the Stateflags
ForEach($Location in $Locations)
{
Remove-ItemProperty -Path $($Base+$Location) -Name $SageSet -Force -ea silentlycontinue | Out-Null
}
Hope this helps