Skip to main content
Windows 10Windows Server

How to Run Disk Cleanup (Cleanmgr.exe) on Windows Server 2016/2012 R2/2008 R2

By August 26, 2020October 4th, 2020No Comments

The Disk Cleanup tool allows the administrator to quickly clean up the Windows Server system drive by deleting unnecessary and temporary files, including cleaning the WinSxS directory from files of outdated components that remained after installing the latest cumulative updates. The Disk Cleanup utility (cleanmgr.exe) is installed by default on the GUI editions of Windows Server 2016/2019 (Desktop Experience). However, in previous versions of Windows Server (2012 R2/2012/2008 R2), the cleanmgr.exe tool is missing.

Using Disk Cleanup Tool on Windows Server 2016

To clean the system disk from unneeded files on Windows Server 2016 using the Disk Cleanup utility, you need to open the disk properties in File Explorer and click the Disk Cleanup button.

run disk cleanup on windows server

You can also type the “disk cleanup” or cleanmgr.exe in the search box.

Select the drive you want to clean.

select drive to cleanup

Wait until the cleaning wizard checks your disk and finds unnecessary files that can be safely deleted.

disk cleanup: scanning drive

You can select components whose files can be deleted. You are prompted to delete the following temporary files:

  • Setup Log Files;
  • Downloaded Program Files;
  • Temporary Internet Files;
  • Recycle Bin;
  • Temporary files;
  • Thumbnails.

To remove unneeded system files, click on the Clean up system files button.

select option to cleanup and free space

Additionally, it is suggested to clean up:

  • Outdated Windows Defender files;
  • System archived Windows Error Reporting files (the folder C:ProgramDataMicrosoftWindowsWERReportQueue);
  • System queued Windows Error Reporting;
  • Device driver packages;
  • Windows Update Cleanup — this allows you to clean up the component store in the WinSxS directory. Old versions of components files that remain after installing updated ones are removed.
cleanup system files on windows server

Select the options you need, and Disk Cleanup will show the amount of disk space you gave. Click OK and confirm the deletion of files.

confirm disk cleanup task

Wait for the cleanmgr.exe tool to remove the unnecessary files.

Cleanmgr.exe: Disk Cleanup Command-Line Options

The cleanmgr.exe tool has several command-line options that allow it to be used in various automatic drive cleaning scenarios. They can be used both on Windows Server and on user desktop workstations running Windows 10.

cleanmgr.exe [/d driveletter] [/SAGESET:n | /SAGERUN:n | TUNEUP:n | /LOWDISK | /VERYLOWDISK | /SETUP | /AUTOCLEAN]

cleanmgr.exe command line options

The /AUTOCLEAN parameter is used to delete old files left after upgrading a Windows build. The /SETUP option allows you to delete files left from a previous version of Windows (if you performed an in-place upgrade).

The cleanmgr /LOWDISK command runs the Disk Cleanup GUI with the already selected cleaning options.

cleanmgr LOWDISK

The cleanmgr /VERYLOWDISK command performs automatic drive cleanup (without showing GUI), and after the end it displays information about the actions performed and available free space.

You have successfully resolved the low disk space condition. Your C: volume now has 10000 Mb of free space remaining.
You have successfully resolved the low disk space condition

Using the /sageset:xx and /sagerun:xx options, you can create and run a customized set of cleanup options.

For example, run the command: cleanmgr /sageset: 11. In the window that opens, select the components and files that you want to automatically cleanup (I selected all the options).

These settings are saved to the registry key HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCaches. This registry section lists all the Windows components that can be cleaned using the Disk Cleanup tool. For each option you select, a DWORD parameter is created with the name StateFlags0011 (0011 is the number you specified in the sageset parameter).

registry CurrentVersion Explorer VolumeCaches stateflags cleanmgr

To start the drive cleanup task with the selected parameters, run the command:

cleanmgr /sagerun:11

If you need to configure automatic disk cleanup task on computers (or servers) in an Active Directory domain, you just need to export this registry key and deploy it on computers through the GPO.

To automatically cleanup the system drive on workstations with Windows 10, you can create a simple scheduled task with the following PowerShell code:

Start-Process -FilePath CleanMgr.exe -ArgumentList '/sagerun:11' -WindowStyle Hidden -Wait

How to Enable Disk Cleanup on Windows Server 2012 R2/2008 R2 without Installing Desktop Experience

By default, in Windows Server 2012/R2 and 2008/R2 the Disk Cleanup (cleanmgr.exe) tool is not installed by default. To use the cleanmgr utility, first you have to install a separate server Desktop Experience feature using either Server Manager or PowerShell (Install-WindowsFeature Desktop-Experience).

Together with Desktop Experience, many other unnecessary components are installed on the server:

  • Windows Media Player;
  • Desktop themes;
  • AVI support for Windows;
  • Windows SideShow;
  • Windows Defender Antivirus;
  • Disk Cleanup;
  • Sync Center;
  • Audio recording;
  • Character Map;
  • Snipping Tool.
Desktop Experience feature on Windows server 2012 R2

To run the Disk Cleanup on Windows Server, you can use a simple method: just copy two files Cleanmgr.exe and Cleanmgr.exe.mui from WinSxS to the system32 directory. Below you can see commands to copy cleanmgr files in different Windows versions (in all cases, the path is used for Windows Server English language editions).

OS versionCommand to copy cleanmgr bin files
Windows Server 2008 R2 x64 copy C:Windowswinsxsamd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7dacleanmgr.exe C:WindowsSystem32
copy C:Windowswinsxsamd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63cleanmgr.exe.mui C:WindowsSystem32en-US
Windows Server 2008 x64 copy C:Windowswinsxsamd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_c962d1e515e94269cleanmgr.exe C:WindowsSystem32
copy C:Windowswinsxsamd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_b9f50b71510436f2cleanmgr.exe.mui C:WindowsSystem32en-US
Windows Server 2012 x64 copy C:WindowsWinSxSamd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.2.9200.16384_none_c60dddc5e750072acleanmgr.exe C:WindowsSystem32
copy C:WindowsWinSxSamd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.2.9200.16384_en-us_b6a01752226afbb3cleanmgr.exe.mui C:WindowsSystem32en-US

Windows Server 2012 R2 x64

The trick described above doesn’t work on Windows Server 2012 R2 due to the changes made by KB2821895 update. The issue is that after you install this update, compression is used to store the binary component files. When you trying to run the copied cleanmgr.exe, the following error appears:

Unsupported 16-Bit Application

The Program or feature ??C:Windowssystem32cleanmgr.exe cannot start or run due to incompatibility with 64-bit version of Windows.
Unsupported 16-Bit Application The Program or feature ??C:Windowssystem32cleanmgr.exe cannot start or run due to incompatibility with 64-bit version of windows

As a workaround, you can use this method:

  1. Install Desktop Experience feature using PowerShell: Install-WindowsFeature Desktop-Experience
  2. Restart your server;
  3. Copy the files %windir%system32cleanmgr.exe and %windir%system32en-UScleanmgr.exe.mui to any directory (c:temp);
  4. Uninstall the feature: Uninstall-WindowsFeature Desktop-Experience
  5. Reboot;
  6. Copy the files cleanmgr.exe and cleanmgr.exe.mui to the directories mentioned above.

Later both of the files can be copied to other servers or integrated into your Windows Server 2012 R2 virtual machine template.

To start the Disk Cleanup tool, run the cleanmgr.exe command with the administrator privileges. 
Tip. You can use the DISM command to delete outdated component files left after installing updates on Windows Server R2:

dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase

To use cleanmgr.exe to delete old update files on Windows 2008 R2 / Windows 7 SP1, you need to install a separate patch KB2852386.

Using Disk Cleanup on Windows Server Core Edition

In Windows Server Core 2016, which lacks full-fledged GUI capabilities, Disk Cleanup tool is also not installed. If you want to use cleanmgr.exe to clean up the disk on Server Core, just copy the following files from the WinSXS directory:

copy C:WindowsWinSxSamd64_microsoft-windows-cleanmgr_31bf3856ad364e35_10.0.14393.0_none_9ab8a1dc743e759acleanmgr.exe C:WindowsSystem32copy C:WindowsWinSxSamd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_10.0.14393.0_en-us_8b4adb68af596a23cleanmgr.exe.mui C:WindowsSystem32en-US

Leave a Reply