Forum Discussion
Nivlee
Feb 26, 2019Copper Contributor
Windows Server ScheduledDefrag Task Schedule not running
All my Windows server (2008 R2 and above) unable to run scheduled task of disk defragmentation? I had turn on the schedule defragmentation in disk defragmenter and set it run on weekly basic, but, it...
ultramage
Apr 17, 2023Copper Contributor
Hi, I saw this unresolved thread, and just want to add that:
- -k selects the 'slab consolidation' task, which seems to be specific to virtual disks and Storage Spaces arrays. For example, defrag on hyper-v VMs show disks as 'Thin Provisioned Drive' and talks about 'space efficiency' and 'evictable slabs'. And it actually runs there. I don't know what it actually does... maybe it tells the backend to defragment the virtual disk?
- -d selects 'traditional defrag' task. Also runs if no task is specified (previous Windows used this).
- Adding -o overrides the task choice and performs 'proper optimization for each media type'.
- If you look at Windows 10 ScheduledDefrag task, it has -o. Server2012R2 and above have -k.
This is why servers no longer defragment automatically. I do not know what the official guidance is for server operators. My guess is that you would alter the task or create a new custom one that fits your environment. That would also involve choosing which disks to optimize and which to skip, and choosing what time to run at to avoid conflicting with backups and to not optimize all VMs simultaneously. This complexity may be why it's effectively turned off by default.
Regarding the missing triggers and schedule:
- Classic scheduled tasks, and tasks created in the Task Scheduler UI, use <CalendarTrigger> to define the schedule. This is then visible in the UI.
- Maintenance tasks instead use <MaintenanceSettings> and integrate into the Automatic Maintenance functionality. You can see this if you export the builtin task and view the xml file. I think this is a Windows 8 feature, and the classic Task Scheduler UI has not been kept up to date.