Delete' Windows.old' folder using powershell

  • Delete' Windows.old' folder using powershell

    Posted by Roddy Gelberty on 21 July 2020 at 4:05 pm

    How can I delete the ‘Windows.old’ folder using a PowerShell script. I want to be able to do this after upgrading Windows to the latest version of Windows 10.
    I understand that Windows automatically deletes this folder but I want to be able to clear this space immediately so that other software distribution activities can continue.

    Roddy Gelberty replied 4 years, 2 months ago 3 Members · 2 Replies
  • 2 Replies
  • Topaz George

    Organizer
    21 July 2020 at 8:21 pm

    Hope this helps.

    If(Test-Path -Path($((Get-WmiObject Win32_OperatingSystem).SystemDrive) +"\windows.old"))
    { 
    	New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations" -Name "StateFlags1221" -PropertyType DWORD  -Value 2 -Force | Out-Null 
    	cleanmgr /SAGERUN:1221 
    }
    
  • Roddy Gelberty

    Member
    21 July 2020 at 9:02 pm

    A few amendments to Topaz’s answer. use ‘start-process‘ cmdlet to start ‘cleanmgr.exe‘.

    If(Test-Path -Path($((Get-WmiObject Win32_OperatingSystem).SystemDrive) +"\windows.old")){ 	New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations" -Name "StateFlags1221" -PropertyType DWORD  -Value 2 -Force | Out-Null 	Start-Process -FilePath "cleanmgr" -ArgumentList /SAGERUN:1221 -Wait -WindowStyle Hidden}

Log in to reply.

DCOM hardening issue.

This application fails to authenticate with WMI on the SCCM server because Microsoft has not yet hardened DCOM on their Windows Preinstallation Environment. We are working on a different approach, but it will only be released during the first quarter of 2024. But until that time, the only workaround will be to uninstall the update corresponding to KB5004442.