Home > Windows Server Tips > Web Management > How to keep IIS logs from filling up your server hard drives
Windows Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

WEB MANAGEMENT

How to keep IIS logs from filling up your server hard drives


Will Schmied, Contributor
03.20.2009
Rating: -4.71- (out of 5)


Expert advice on Windows-based systems and hardware
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


If you're running a version of Microsoft Internet Information Services (IIS) on any of your servers, then you've probably seen what happens when IIS logs are not cleaned up periodically. Old IIS logs can quickly eat up all of the free space on the hard drive, especially on servers with highly utilized websites, such as Microsoft Outlook Web Access or line-of-business applications.

Instead of having to check and clear IIS logs manually, wouldn't it be nice to have a scheduled task that deletes the old logs automatically? The solution is easily implemented with a simple Visual Basic script and a scheduled task on each of the servers you want to keep cleaned up.

To clear the old IIS logs, or any type of log file that accumulates over time, you'll need to first save the script presented below with the extension of .vbs, such as delete_old_logs.vbs. I like to put all of the maintenance scripts I place on a server in a specific directory that I create, which in my case is C:\Program Files\Scripts. But you can save the script file anywhere on the server.

After the script has been saved on the server, you'll need to edit the script to specify the exact path that is to be cleaned and how many days of log files should be left. You'll find this information in the line that starts with Call CleanDirectory. In the example below, the script is set to delete the default IIS logs that are older than seven days. Be sure your folder path is inside the quotation marks, and remember that you can insert multiple Call CleanDirectory lines if you'd like to delete logs from several sources on the same server simultaneously. After making your changes to the script, be sure to save the script file.

The last step is to schedule a task to run the script file. The account that you run the scheduled task under needs to have permissions on the folders where the log files are located, so it's usually best to create a spec...


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
Microsoft Internet Information Services (IIS)
Small changes go a long way with IIS 7.5
IIS gets patched, SQL Server not so much
Internet Information Services (IIS) sees big changes in Windows Server 2008
A first look at Internet Information Services 7.0
Free security tools that can improve IIS security
New IIS 7 security adds value to Windows Server 2008
How can I prevent Internet access with Windows SBS?
When and how to use worker process recycling with IIS
Windows Process Activation Service in IIS 7.0
How to use Microsoft's IIS Diagnostics Toolkit

Windows Data Storage Administration Tools
eZines and eBooks for Windows server professionals
Quick tips for troubleshooting NTFS permissions
Using NTFS on a non-Windows OS with NTFS-3G
Server Message Block 2.0: A new protocol for the millennium
Top Windows storage improvements for cutting costs in '09
Breaking down the Windows Server Backup tool for Windows 2008
A first look at Storage Explorer for Windows Server 2008
Windows scripting secrets for disk quota management
Top 10 Windows storage management tips of 2007
Exploring the Windows Server 2003 Resource Kit: Compress.exe and Expand.exe

Windows PowerShell Scripting
Microsoft brings PowerShell 2.0 to the masses
Top 25 Windows PowerShell commands for administrators
Getting started with Windows PowerShell and Microsoft Hyper-V
Scripting secrets for reviewing Windows event log data
Windows scripting tutorials for systems administrators
Extending your toolset with Windows PowerShell
PowerShell Community Extensions and PowerShell Plus
Windows PowerShell for beginners
Downloading and Installing Windows PowerShell
What is Windows PowerShell?

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
IIS  (SearchWindowsServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


ial account (local or domain) and put that account in the local server administrations group. This will allow the script to perform its intended function in any location on the server.

When you create the scheduled task, you'll need to browse to the location where you saved the file. Make sure the path is enclosed in quotation marks if it contains any spaces. For best results, schedule the task to run daily.

With just a few simple steps, you can quickly implement a proactive solution on your servers to keep IIS logs from completely filling up your hard drives. Since Internet Information Services is not the only application that has a habit of creating lots of log files, I'm sure you'll find plenty of uses for this cleanup script.

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' delete_old_files.vbs
' Based on original script here:
'
http://www.microsoft.com/technet/scriptcenter/csc/scripts/files/files/cscfi006.mspx
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

' Clean the listed directories of old backup files
Call CleanDirectory("C:\WINDOWS\system32\LogFiles\W3SVC1", 7)

' Delete old backup files
Function CleanDirectory(strPathtoFiles, intDaystoKeep)
   Dim fso, f, fc, f1, strFiles, intFiles
   strFiles = ""
   intFiles = 0

   Set fso = CreateObject("Scripting.FileSystemObject")
   If (fso.FolderExists(strPathtoFiles)) Then
      Set f = fso.GetFolder(strPathtofiles)
      Set fc = f.Files

      '-- Determine if file is older than defined days
      For Each f1 in fc
         If DateDiff("d", f1.DateLastModified, Now) > intDaystoKeep Then
            strFiles = strFiles & f1.Name & vbCrLf
            intFiles = intFiles + 1
            f1.Delete(True)
         End If
      Next

      Set f1 = Nothing
      Set fc = Nothing
      Set f = Nothing

   End if

   set fso = Nothing

End Function

' Stop the script in case it doesn't automatically WScript.Quit


[IMAGE]Will Schmied is a senior systems administrator for a world renowned children's research hospital. He holds numerous Microsoft MCITP, MCTS and older certifications and is experienced with Exchange and Blackberry. Will has been actively involved with the certification and training side of IT for many years, writing or contributing to several dozen books. He is a founder of the certification portal MCSE World. Having passed the reigns to a good friend from down under, Will maintains a smaller presence today with his blog, Tales of a Systems Administrator.


Rate this Tip
To rate tips, you must be a member of SearchWindowsServer.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Server Room Design - Planning, Cooling, Maintenance
HomeTopicsBlogsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2004 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts