Earlier today I was looking for a script to remove the c:\Windows.old directory from my computer following installation of a new version of Windows. Unfortunately, in these times of “Windows 10 is the last desktop OS we will ever deliver, but we are updating it to a new version every six months,” this is needed now more than ever.
The script that I dug up I did not write. I think I borrowed it from TechNet a few years ago. However, it works well, so feel free to use it! -M
$path = $env:HOMEDRIVE+”\windows.old”
If(Test-Path -Path $path)
{
#create registry value
$regpath = “HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations”
New-ItemProperty -Path $regpath -Name “StateFlags1221” -PropertyType DWORD -Value 2 -Force | Out-Null
#start clean application
cleanmgr /SAGERUN:1221
}
Else
{
Write-Warning “There is no ‘Windows.old’ folder in system driver”
cmd /c pause
}
Leave a Reply