เครื่องมือ Disk Cleanup ช่วยให้ผู้ดูแลระบบทำความสะอาด system drive ของ Windows Server ได้อย่างรวดเร็วโดยการลบไฟล์ที่ไม่จำเป็นและไฟล์ชั่วคราว รวมถึงการทำความสะอาดไดเรกทอรี WinSxS จากไฟล์ของ components เก่าที่เหลือหลังจากติดตั้ง cumulative updates ล่าสุด ยูทิลิตี้ Disk Cleanup (cleanmgr.exe) ติดตั้งโดยค่าเริ่มต้นบน GUI editions ของ Windows Server 2016/2019 (Desktop Experience) อย่างไรก็ตาม ใน Windows Server เวอร์ชันก่อนหน้า (2012 R2/2012/2008 R2) เครื่องมือ cleanmgr.exe หายไป
การใช้ Disk Cleanup Tool บน Windows Server 2016
เพื่อทำความสะอาด system disk จากไฟล์ที่ไม่จำเป็นบน Windows Server 2016 โดยใช้ Disk Cleanup utility คุณต้องเปิดคุณสมบัติดิสก์ใน File Explorer และคลิกปุ่ม Disk Cleanup

คุณยังสามารถพิมพ์ "disk cleanup" หรือ cleanmgr.exe ในกล่องค้นหา
เลือกไดรฟ์ที่คุณต้องการทำความสะอาด
รอจนกว่า cleaning wizard จะตรวจสอบดิสก์ของคุณและค้นหาไฟล์ที่ไม่จำเป็นที่สามารถลบได้อย่างปลอดภัย

คุณสามารถเลือก components ที่ไฟล์ของพวกเขาสามารถลบได้ คุณจะได้รับแจ้งให้ลบไฟล์ชั่วคราวต่อไปนี้:
- Setup Log Files;
- Downloaded Program Files;
- Temporary Internet Files;
- Recycle Bin;
- Temporary files;
- Thumbnails.
เพื่อลบ system files ที่ไม่จำเป็น ให้คลิกปุ่ม Clean up system files

เพิ่มเติมเสนอให้ทำความสะอาด:
- Outdated Windows Defender files;
- System archived Windows Error Reporting files (โฟลเดอร์ C:\ProgramData\Microsoft\Windows\WER\ReportQueue);
- System queued Windows Error Reporting;
- Device driver packages (ดู How to Remove Unused Drives from Driver Store);
- Windows Update Cleanup — นี่ช่วยให้คุณทำความสะอาด component store ในไดเรกทอรี WinSxS ไฟล์เวอร์ชันเก่าของ components ที่เหลือหลังจากติดตั้งอัปเดตใหม่จะถูกลบ
เลือกตัวเลือกที่คุณต้องการ และ Disk Cleanup จะแสดงปริมาณพื้นที่ดิสก์ที่คุณได้รับ คลิก OK และยืนยันการลบไฟล์

รอจนกว่า cleanmgr.exe tool จะลบไฟล์ที่ไม่จำเป็น
Cleanmgr.exe: ตัวเลือกบรรทัดคำสั่ง Disk Cleanup
เครื่องมือ cleanmgr.exe มีตัวเลือกบรรทัดคำสั่งหลายอย่างที่ช่วยให้ใช้ได้ในสถานการณ์การทำความสะอาดไดรฟ์อัตโนมัติต่างๆ พวกเขาสามารถใช้ได้ทั้งบน Windows Server และเวิร์กสเตชันเดสก์ท็อปที่รัน Windows 10
cleanmgr.exe [/d driveletter] [/SAGESET:n | /SAGERUN:n | TUNEUP:n | /LOWDISK | /VERYLOWDISK | /SETUP | /AUTOCLEAN]

พารามิเตอร์ /AUTOCLEAN ใช้ลบไฟล์เก่าที่เหลือหลังจากอัปเกรด Windows build พารามิเตอร์ /SETUP ช่วยให้คุณลบไฟล์ที่เหลือจาก Windows เวอร์ชันก่อนหน้า (หากคุณทำ in-place upgrade)
คำสั่ง cleanmgr /LOWDISK รัน Disk Cleanup GUI พร้อมตัวเลือกการทำความสะอาดที่เลือกไว้แล้ว

คำสั่ง cleanmgr /VERYLOWDISK ทำความสะอาดไดรฟ์อัตโนมัติ (โดยไม่แสดง GUI) และหลังสิ้นสุดแสดงข้อมูลเกี่ยวกับการดำเนินการที่ทำและพื้นที่ว่างที่มีอยู่
You have successfully resolved the low disk space condition. Your C:\ volume now has 10000 Mb of free space remaining.

โดยใช้ตัวเลือก /sageset:xx และ /sagerun:xx คุณสามารถสร้างและรันชุดตัวเลือกการทำความสะอาดที่กำหนดเองได้
ตัวอย่างเช่น รันคำสั่ง: cleanmgr /sageset: 11 ในหน้าต่างที่เปิด ให้เลือก components และไฟล์ที่คุณต้องการทำความสะอาดอัตโนมัติ (ผมเลือกทุกตัวเลือก)
การตั้งค่านี้ถูกบันทึกลงในคีย์รีจิสทรี HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches ส่วนรีจิสทรีนี้แสดงรายการ components ทั้งหมดของ Windows ที่สามารถทำความสะอาดได้โดยใช้ Disk Cleanup tool สำหรับแต่ละตัวเลือกที่คุณเลือก จะมีพารามิเตอร์ DWORD สร้างขึ้นด้วยชื่อ StateFlags0011 (0011 คือหมายเลขที่คุณระบุในพารามิเตอร์ sageset)

เพื่อเริ่มงานทำความสะอาดไดรฟ์ด้วยพารามิเตอร์ที่เลือก ให้รันคำสั่ง:
cleanmgr /sagerun:11
หากคุณต้องการกำหนดค่าการทำความสะอาดดิสก์อัตโนมัติบนคอมพิวเตอร์ (หรือเซิร์ฟเวอร์) ในโดเมน Active Directory คุณเพียงแค่ต้องส่งออกคีย์รีจิสทรีนี้และปรับใช้บนคอมพิวเตอร์ผ่าน GPO
เพื่อทำความสะอาด system drive อัตโนมัติบนเวิร์กสเตชันที่มี Windows 10 คุณสามารถสร้าง scheduled task เรียบง่ายด้วยโค้ด PowerShell ต่อไปนี้:
Start-Process -FilePath CleanMgr.exe -ArgumentList '/sagerun:11' -WindowStyle Hidden -Wait
วิธีเปิดใช้งาน Disk Cleanup บน Windows Server 2012 R2/2008 R2 โดยไม่ติดตั้ง Desktop Experience
โดยค่าเริ่มต้น ใน Windows Server 2012/R2 และ 2008/R2 เครื่องมือ Disk Cleanup (cleanmgr.exe) ไม่ได้ติดตั้งโดยค่าเริ่มต้น เพื่อใช้ cleanmgr utility ขั้นแรกคุณต้องติดตั้ง server Desktop Experience feature แยกต่างหากโดยใช้ Server Manager หรือ PowerShell (Install-WindowsFeature Desktop-Experience)
ร่วมกับ Desktop Experience components ที่ไม่จำเป็นอื่นๆ มากมายถูกติดตั้งบนเซิร์ฟเวอร์:
- Windows Media Player;
- Desktop themes;
- AVI support for Windows;
- Windows SideShow;
- Windows Defender Antivirus;
- Disk Cleanup;
- Sync Center;
- Audio recording;
- Character Map;
- Snipping Tool.

เพื่อรัน Disk Cleanup บน Windows Server คุณสามารถใช้วิธีง่ายๆ: เพียงคัดลอกสองไฟล์ Cleanmgr.exe และ Cleanmgr.exe.mui จาก WinSxS ไปยัง system32 directory ด้านล่างคุณสามารถเห็นคำสั่งในการคัดลอก cleanmgr binary files ใน Windows versions ต่างๆ (ในทุกกรณี เส้นทางใช้สำหรับ Windows Server English language editions)
| OS version | คำสั่งคัดลอก cleanmgr binary files |
| Windows Server 2008 R2 x64
|
copy C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe C:\Windows\System32\ |
| Windows Server 2008 x64
|
copy C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_c962d1e515e94269\cleanmgr.exe C:\Windows\System32\ |
| Windows Server 2012 x64
|
copy C:\Windows\WinSxS\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.2.9200.16384_none_c60dddc5e750072a\cleanmgr.exe C:\Windows\System32\ |
Windows Server 2012 R2 x64
ทริกที่อธิบายข้างต้นไม่ทำงานบน Windows Server 2012 R2 เนื่องจากการเปลี่ยนแปลงที่ทำโดย KB2821895 update เรื่องคือหลังจากที่คุณติดตั้งอัปเดตนี้ การบีบอัดถูกใช้เพื่อเก็บ binary component files เมื่อคุณพยายามรัน cleanmgr.exe ที่คัดลอกมา ข้อผิดพลาดต่อไปนี้จะปรากฏ:
Unsupported 16-Bit Application The Program or feature \??\C:\Windows\system32\cleanmgr.exe cannot start or run due to incompatibility with 64-bit version of Windows.

ในฐานะ workaround คุณสามารถใช้วิธีนี้:
- ติดตั้ง Desktop Experience feature โดยใช้ PowerShell:
Install-WindowsFeature Desktop-Experience - รีสตาร์ทเซิร์ฟเวอร์ของคุณ;
- คัดลอกไฟล์ %windir%\system32\cleanmgr.exe และ %windir%\system32\en-US\cleanmgr.exe.mui ไปยังไดเรกทอรีใดๆ (c:\temp);
- ถอนการติดตั้ง feature:
Uninstall-WindowsFeature Desktop-Experience - Reboot;
- คัดลอกไฟล์ cleanmgr.exe และ cleanmgr.exe.mui ไปยังไดเรกทอรีที่กล่าวมาข้างต้น
ภายหลังทั้งสองไฟล์สามารถคัดลอกไปยังเซิร์ฟเวอร์อื่นๆ หรือรวมเข้าไปใน Windows Server 2012 R2 virtual machine template ของคุณ
เพื่อเริ่ม Disk Cleanup tool ให้รันคำสั่ง cleanmgr.exe ด้วยสิทธิ์ administrator 
Tip คุณสามารถใช้คำสั่ง DISM เพื่อลบไฟล์ component เก่าที่เหลือหลังจากติดตั้งอัปเดตบน Windows Server R2:
dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
เพื่อใช้ cleanmgr.exe ลบไฟล์อัปเดตเก่าบน Windows 2008 R2 / Windows 7 SP1 คุณต้องติดตั้งแพทช์แยกต่างหาก KB2852386
การใช้ Disk Cleanup บน Windows Server Core Edition
ใน Windows Server Core 2016 ซึ่งขาดความสามารถ GUI เต็มรูปแบบ Disk Cleanup tool ก็ไม่ได้ติดตั้งเช่นกัน หากคุณต้องการใช้ cleanmgr.exe ทำความสะอาดดิสก์บน Server Core เพียงแค่คัดลอกไฟล์ต่อไปนี้จาก WinSXS directory:
copy C:\Windows\WinSxS\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_10.0.14393.0_none_9ab8a1dc743e759a\cleanmgr.exe C:\Windows\System32\copy C:\Windows\WinSxS\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_10.0.14393.0_en-us_8b4adb68af596a23\cleanmgr.exe.mui C:\Windows\System32\en-US\