search
top

How to Squeeze More Space on Your Windows C drive

As a system administrator you are always fighting the battle to keep the C:\ drive as clean as possible, which at times can be a job in itself. In this post we will discuss a few places where you can get a few more MB or GB from the drive. These tricks apply on Windows 2003, 2008, 2008 R2, 2012 and 2012 R2.

Compress c:\windows\installer directory

You can gain about half the space used by this folder by compressing it. First we need to unhide the folder then compress it.

Un-Hide the folder

  • Click on the C:\Windows folder and click Organize> Folder and search options.
  • Un-check Hide Protected operating system files (Recommended)
  • Check Show Hidden files, folders and drives.
  • Apply and Apply to All Folders.

cleanup2

Now let’s compress the folder.

  • Right-click the installer folder
  • Properties
  • Click on Advanced button

cleanup3

  • Click on Compress folder. Click OK
    cleanup4
  • Apply for all files and folder. You may receive a popup.

cleanup5

Note: After done make sure to go back and re-check Hide Protected operating system files (Recommended).

Remove Recycle Bin

This cleanup has been covered in a previous post found here.

Reduce System Volume drive

This is another topic that has been discussed in a previous post also referred to as disappearing space. This is usually caused by Volume Shadow Storage space and is easily rectified by defining how much space can be used by a drive for Shadow Storage.

IIS Logs

The IIS logs are notorious for silently filling up the C:\ drive on systems. You can delete them manually or from a command line.

Windows 2003

The IIS Logs are located in c:\windows\system32\LogFiles directory. There will be directories starting with W3SVC in the name and for FTP will have MSFTPSVC in the name. Delete the log files in the directories with the exception of the current date logfile if you are so inclined. Another way is to use command line and a utility called forfiles. The nice thing about command line is that you create a cmd file and schedule it to run nightly. At the bottom of this post there will be an example cmd file and the syntax to add it as a scheduled task running as system

This command line example shows how to delete files ending in .log that are older than 14 days and the /s switch allows it to handle sub-directories.

forfiles /p %SYSTEMROOT%\system32\LogFiles /s /m *.log /d -14 /c "cmd /c del @file"

Windows 2008 R2 / 2012 R2

As with Windows 2003 example the same goes for Windows 2008 R2 and 2012 R2, only difference is the log file location is changed to C:\inetpub\logs . You can delete them manually or use the command line.

forfiles /p C:\inetpub\logs /s /m *.log /d -14 /c "cmd /c del @file"

C:\Windows\Temp directory Cleanup

There are several places where you can reclaim some space in c:\windows\temp directory. The following list is some of the files that can be deleted safely, there are always more. You can also ad many to a script and run as a scheduled task.

  • psscript_output*.txt
  • *.tmp
  • Any directories with KB in the name
  • Any KB*.txt
  • Any KB*.html
  • Any Microsoft* directories (Usually Microsoft Visual C++ and others similar in name.
  • Any Microsoft*.txt files
  • Any Microsoft*.html files
  • Any *.sqm files

Want to do it from the command line, Here you go. this example shows 0 days and no sub-directories.

forfiles /p C:\Windows\Temp /m psscript_output*.txt /d -1 /c “cmd /c del @file”
forfiles /p C:\Windows\Temp /m *.tmp /d -1 /c “cmd /c del @file”
forfiles /p C:\Windows\Temp /m KB*.txt /d -0 /c “cmd /c del @file”
forfiles /p C:\Windows\Temp /m KB*.html /d -0 /c “cmd /c del @file”
forfiles /p C:\Windows\Temp /m Microsoft*.txt /d -0 /c “cmd /c del @file”
forfiles /p C:\Windows\Temp /m Microsoft*.html /d -0 /c “cmd /c del @file”
forfiles /p C:\Windows\Temp /m *.sqm /d -0 /c “cmd /c del @file”

The C:\windows\winsxs directory

This is the directory that gets the most questions which also leads to the most disappointment. You can recover space from this directory by using Disk Cleanup tool. To use it you must have the Windows Desktop Experience installed. Refer to this post on how to enable and use Disk Cleanup.

User Profiles

Another place to look for space is in old user profiles from long gone admins or users. These are easy to remove.

  • Click Start, right-click My Computer, and then click Properties.
  • In the System Properties dialog box, click the Advanced tab.
  • Under User Profiles, click Settings.
  • Click the user profile that you want to delete, and then click Delete. Do not delete any service accounts or builtin accounts (Administrator, Guest).

 

Sample Script

So let’s take this a bit farther and create a command script and run it as a scheduled task for some of the files and log it to the Application log so there is a record.

REM ****************************************************************************
REM FILE: Cleanup.cmd
REM PURPOSE: To delete old logs and files after XX days
REM USAGE: Cleanup.cmd
REM REQUIREMENTS: Windows 2003/2008/2012
REM HISTORY: v1.0
REM *****************************************************************************

 

REM ** put Starting message in Application Log
%SYSTEMROOT%\system32\eventcreate.exe /T INFORMATION /L APPLICATION /SO Cleanup /ID 101 /D Starting-Scheduled-Task-to-maintain-Drive-files

REM ************************************
REM * Clean up logs older than 14 days
REM ************************************
forfiles /p %SYSTEMROOT%\system32\LogFiles /s /m *.log /d -14 /c “cmd /c del @file”
forfiles /p C:\inetpub\logs /s /m *.log /d -14 /c “cmd /c del @file”

REM Clear out files out of c:\windows\temp
forfiles /p C:\Windows\Temp /m psscript_output*.txt /d -1 /c “cmd /c del @file”
forfiles /p C:\Windows\Temp /m *.tmp /d -1 /c “cmd /c del @file”
forfiles /p C:\Windows\Temp /m KB*.txt /d -0 /c “cmd /c del @file”
forfiles /p C:\Windows\Temp /m KB*.html /d -0 /c “cmd /c del @file”
forfiles /p C:\Windows\Temp /m Microsoft*.txt /d -0 /c “cmd /c del @file”
forfiles /p C:\Windows\Temp /m Microsoft*.html /d -0 /c “cmd /c del @file”
forfiles /p C:\Windows\Temp /m *.sqm /d -0 /c “cmd /c del @file”

 

REM ** put Completion message in Application Log
%SYSTEMROOT%\system32\eventcreate.exe /T INFORMATION /L APPLICATION /SO Cleanup /ID 201 /D Completed-Scheduled-Task-to-maintain-Drive-files

Save the script as Cleanup.cmd or what name you desire. and now to add it to run nightly. In this example we will run the script from the c:\scripts directory as SYSTEM at 4:15 am.

schtasks /Create /SC DAILY /RU “SYSTEM” /TN Cleanup /ST 04:15 /TR c:\scripts\Cleanup.cmd

As you can see there are several places and ways to get more space available on your C drive in Windows.

 

 

One Response to “How to Squeeze More Space on Your Windows C drive”

  1. Lorena says:

    Very helpful information! Thank you for taking the time to create this 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

top