We can launch disk cleanup tool from Run window by executing the command cleanmgr.
There are two command line switches that cleanmgr command accepts. These can be used to automate the disk cleanup task. These two switches are /sageset and /sagerun.
To perform unattended disk cleanup we need to perform the following steps.
1. Create disk cleanup settings by running the following command
This will launch disk cleanup tool. Now you need to select the categories of files you want to delete. Click on ‘OK’ button after selecting the items.
2. Now whenever you want automated disk cleanup, you just need to run the below command.
This works on Windows XP, Vista, Windows 7, Server 2003 and Server 2008 operating systems.