How to clean up a Windows server

Last Updated on April 24, 2017 by Dave Farquhar

From time to time, Windows patches will fail to install because a server doesn’t have enough space to install them. Finding the ginormous files are that are hogging all the space on the C drive is really tedious if you do it by clicking around in Windows Explorer, but there’s a better way.

Download the free Sysinternals Du.exe utility and you can find the behemoths in minutes, if not seconds. If you have Unix experience, you might think this utility sounds similar to the Unix du utility. You would be correct. Download the utility, extract the zip file, save the executable somewhere in your system path–some people frown on copying tools straight into C:\Windows but I do it anyway–then open a command prompt and go to town.

Here’s an example of how I put it to work:

DU -L 1 \\servername\c$

I used capital letters for clarity, but the command isn’t case-sensitive. This command immediately tells me the size of every subdirectory right off the root of the drive. Then, when I see what high-level directory is hogging space, I can drill down another level:

DU -L 1 \\servername\c$\users

Often the biggest hogs on a server are the user profiles because a sysadmin copies installation files onto his or her desktop, performs the installation, then leaves the files there just in case, where they sit for the better part of a decade. Some companies have cryptic usernames, so to find out who’s hogging the space if you can’t figure it out, copy the user ID, then compose an e-mail message in Outlook (assuming you’re an Exchange shop), paste the user ID into the To: field, and hit <Ctrl-K> to resolve the name. While you’re there, you might as well go ahead and compose a message asking the person to go clean out the profile to free up some space.

For better speed, you can also run it straight on the server.

DU -L 1 c:\

DU -L 1 c:\users

Don’t forget to look in the root directory. On one server I found an obnoxious 4 gb log file from a software installation someone did in 2011 sitting in the root directory. The log file was taking more space on the server than the application itself, so I have no idea what was up with that.

Once you find the giant files that are keeping you from securing the machines, move them to a different drive or a different machine, compress them, or delete them–whatever you have to do.

After the cleanup, if you have time and can get two maintenance windows, think about defragmenting the drive before you patch. This will make the patching and subsequent reboot go faster, in addition to improving performance during the day and making future patch/reboot cycles go faster.

For doing large numbers of servers, you can script DU as well.

If you found this post informative or helpful, please share it!

2 thoughts on “How to clean up a Windows server

  • September 12, 2014 at 8:35 am
    Permalink

    du is nice. When I have to work together with a non-CLI guy I tend to go with WinDirStat; it’s surprisingly small and powerful for a GUI tool and gives a nice graphic overview of the space used by files and directories (and filetypes), and you can trash or perma-delete right from there.

    I just recommended a GUI sysadmin tool. I think Jesus can come back now.

  • September 12, 2014 at 5:25 pm
    Permalink

    Not only a GUI sysadmin tool, but a Windows one at that. Albeit an open-source one.

    Thanks for the recommendation of Windirstat though, because I probably have to work with non-CLI guys more often than not myself.

Comments are closed.