New
#1
cleanmgr.exe via Powershell
Hello,
I would like to hear some tips on how to fix the PowerShell script. Generally, it works fine but I want to add something like a timer that I can run a script and it will stop in 15 min anyway! (that the time, when 'clearmgr' usually will complete the task) Why I need that? Cuz I will run it via PDQ Deploy tool for more than 300 computers and it might be stuck sometimes for some reason for an unlimited time so I want to eliminate any freezes or lags.
Please take a look at how to add the correct addition to that script. Or maybe rewrite it and do it differently?
Thank you in advance!
# Create reg keys
$volumeCaches = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches"
foreach($key in $volumeCaches)
{
New-ItemProperty -Path "$($key.PSPath)" -Name StateFlags0099 -Value 2 -Type DWORD -Force | Out-Null
}
# Run Disk Cleanup
Start-Process -Wait "$env:SystemRoot\System32\cleanmgr.exe" -ArgumentList "/sagerun:99"
# Delete the keys
$volumeCaches = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches"
foreach($key in $volumeCaches)
{
Remove-ItemProperty -Path "$($key.PSPath)" -Name StateFlags0099 -Force | Out-Null
}