Windows 10 – Remove Windows.old Folder

Long time no see, huh? Now I’m back with a new post about removing the Windows.old folder after a feature Upgrade.
Recently I seen this on twitter, a commented it with: Why don’t you let the automation from Windows 10 let it do. But since then, I was in a project, where the removal of this folder was required, and within the Upgrade Task Sequence. I thought, this is easy, starting the Scheduled Task should do the job…

You can easily start this task within a command line, but since this does not solve the “problem”, I don’t provide this command. But I will provide a more useful information. You can use cleanmgr.exe, yes, this is the “Disk Cleanup” which is included since some versions of Windows:

But this is a GUI, how can we use this within in TS? I used my prefered search engine, and found a solution. You can create a Cleanup Profile, save this to registry, and then run the profile from command line. Seem cool? Here are the steps:
Go ahead, and start cleanmgr.exe with the following parameters:
cleanmgr.exe /sageset:1703

The parameter sageset instructs the cleanup wizard to save the selected options to the registry. The following number after the parameter sets the profile ID, or number, with which the settings are stored. The Number can be from 0 to 65535, so there might be enough numbering possible.

As soon as the wizard is loaded, you can select all the options you want to include within the cleanup, in my case, I only selected “Previous Windows Installation(s)” as shown in a print screen above. After a click on OK, the wizard writes this settings to the registry under “Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches”, per each setting:

As you can see on the previous picture, every setting from the wizard has a corresponding key within the registry. So if you have selected “Previous Windows Installation(s)”, you will find a new entry under “Previous Installations”, in my case named “StateFlags1703”, where the number from the parameter is represented:

Now you can export this, and import it within the Task Sequence, oder just write it through Powershell with the following command:
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations\" -Name "StateFlags1703" -Type DWORD -Value 2

When this is done, you only need to call cleanmgr.exe with the “sagerun” parameter, and the not (?) documented silent parameter:
cleanmgr.exe /sagerun:1703 /S
Without the /S parameter, the GUI will show up and requires you to press OK, what will not work within a TS.

Hope this helps, and deleting the windows.old folder, I still recommend to do only if required, otherwise let the scheduled task do the magic.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s