IIS log files for WSUS Web Site May Not Be Deleted

Article ID: 2538579 - View products that this article applies to.
Expand all | Collapse all

SYMPTOMS

IIS log files for the WSUS Administration website are filling up the server's hard drive. The log file for the WSUSLOGCLEANER will contain the following error:

1/26/2011 3:13:09 PM             Start deleting WSUS logs

1/26/2011 3:13:09 PM             Failed : Invalid index.  (-2147352565)

The log file is located in the directory c:\program files\windows small business server\logs. On SBS 2008 with SBS Update Rollup 5, the file is named WSUSLOGCLEANER_SCRIPT.LOG. On SBS 2011 Standard, the file is named WSUSLOGCLEANER.LOG

CAUSE

The WSUSlogcleaner scheduled task may be unable to locate the WSUS Administration website and as a result it can't find the directory containing the log files.

RESOLUTION

We have created a new script to replace the original WSUSLOGCLEANER script. The new script uses a different detection method to locate the WSUS Administration website. To resolve this issue we need to replace the existing WSUSLOGCLEANER script with the script contained in this article. 

1. Rename the existing wsuslogcleaner.vbs file located at c:\program files\windows small business server\bin to wsuslogcleaner.old 

2. Open notepad on the server and paste the following script into notepad:

Option Explicit

Dim Servername,ServiceType, RootPath, WebSiteID,  WebSitepath, totalDeleted, MaxAgeOfFileToKeep, ArgObj
Dim strLogLocation,strLogName, objFSO, objLogFile
Dim strKeyPath,strValueName,strComputer,oReg,dwValue


' Delete old log files
Function DeleteOldLogFiles(WebSite,  MaxAgeOfFile,ServiceType,WebSiteID ,objLogFile)
 Dim File, ServerObj, FSO, FolderObj, LogFileDir, Deleted, FailedToDelete
 Deleted = 0
 FailedToDelete = 0
 Set ServerObj = GetObject(WebSite)
 ' Find the true path of the Logs
 LogFileDir = ServerObj.LogFileDirectory & "\"& ServiceType & WebSiteID
 objLogFile.WriteLine(Now & vbTab & "Log file dir for: " &WebSite & " = " & LogFileDir)
 objLogFile.WriteLine(Now & vbTab & "Delete files over "& MaxAgeOfFile & " days old.")
 Set ServerObj = Nothing
 Set FSO = CreateObject("Scripting.FileSystemObject")
 set Folderobj = FSO.GetFolder(LogFileDir)
 ErrorCheck(objLogFile)
 
 for each File in Folderobj.Files
  IF (Date - File.datelastmodIFied  > cint(MaxAgeOfFile)) Then
   Err.Clear
   IF (KillFile = 1) Then
    FSO.DeleteFile(LogFileDir & "\" & File.Name)
    IF (Err.Number <> 0) Then
     FailedToDelete = FailedToDelete +1
     objLogFile.WriteLine(Now & vbTab & "Failed : "& Err.Description & " (" & Err.Number & ")")
    Else
     Deleted = Deleted + 1
    End IF
   End IF
  End IF
 Next
 Err.Clear
 DeleteOldLogFiles = Deleted
 objLogFile.WriteLine(Now & vbTab & "Log file: " &"Deleted = " & Deleted)
 objLogFile.WriteLine(Now & vbTab & "Log file: " &"FailedToDelete = " & FailedToDelete)
end function

' Error check function
Function ErrorCheck(objLogFile)
 IF (Err.Number <> 0) Then
  objLogFile.WriteLine(Now & vbTab & "Failed : "& Err.Description & " (" & Err.Number & ")")
  WScript.Quit(1)
 End IF
end function

' Main Function here
' Const Values
Const KillFile = 1 ' Set this to 0 to not delete the files, set to 1 to delete the files
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
strLogLocation = "..\Logs\" ' Script log path
strLogName =  "WSUSLogCleaner_Script.log" ' Script logfile
Servername = "LocalHost"
ServiceType = "w3svc"
RootPath = "IIS://" & Servername &"/" &ServiceType


on error resume next
' Create script log file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile(strLogLocation&strLogName , 8, True)

' Parse the argument
Set ArgObj = WScript.Arguments
IF ArgObj.Count < 1 Then
 objLogFile.WriteLine("Argument error!"):
 WScript.Quit (1)
End IF
MaxAgeOfFileToKeep = trim(ArgObj(0)) ' maximum age in days of files to keep.

objLogFile.WriteLine(Now & vbTab & "Start deleting WSUS logs")

' Get website ID
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Update Services\Server\Setup"
strValueName = "IISTargetWebSiteIndex"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,WebSiteID
objLogFile.WriteLine(Now & vbTab & "ID: " & WebSiteID)

if IsNull(WebSiteID) Then
 objLogFile.WriteLine(Now & vbTab & "Error : Cannot find website for WSUS")
 WScript.Quit(1)
End if

WebSitepath = RootPath & "/" & WebSiteID
ErrorCheck(objLogFile)


' Delete website logs
objLogFile.WriteLine(Now & vbTab &"WebSitepath: "& WebSitepath)
totalDeleted = DeleteOldLogFiles(WebSitePath,  MaxAgeOfFileToKeep, ServiceType, WebSiteID, objLogFile)
 

' Finished
ErrorCheck(objLogFile)
objLogFile.WriteLine(Now & vbTab & "Deleting logs finished.")
WScript.Quit(0)

3. Save the file as wsuslogcleaner.vbs

4. Copy the new file to c:\program files\windows small business server\bin

The script will automatically every night at 2:00am. You can force the script to run by going into Task Scheduler and running the scheduled task named
WSUSLogCleaner. The task is located in the Task Scheduler Library under the Microsoft/Windows/Windows Small Business Server 2008 or Microsoft/Windows/Windows Small Business Server 2011 Standard branch.

Once the script runs, you can examine the log file to view the results. With the new script, the log file will always be named WSUSLOGCLEANER_SCRIPT and it will be located in the c:\program files\windows small business server\logs directory. A successful log will look similar to the following:

4/15/2011 9:01:51 AM Start deleting WSUS logs
4/15/2011 9:01:51 AM ID: 1572271583
4/15/2011 9:01:51 AM WebSitepath: IIS://LocalHost/w3svc/1572271583
4/15/2011 9:01:51 AM Log file dir for: IIS://LocalHost/w3svc/1572271583 = C:\inetpub\logs\LogFiles\w3svc1572271583
4/15/2011 9:01:51 AM Delete files over 100 days old.
4/15/2011 9:01:51 AM Log file: Deleted = 1
4/15/2011 9:01:51 AM Log file: FailedToDelete = 0
4/15/2011 9:01:51 AM Deleting logs finished.



MORE INFORMATION

The WSUSLOGCLEANER script was first introduced in Small Business Server 2008 Update Rollup 5. The script is also included with Small Business Server 2011 Standard.
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Properties

Article ID: 2538579 - Last Review: April 21, 2011 - Revision: 4.0
APPLIES TO
  • Windows Small Business Server 2008 Standard
  • Windows Small Business Server 2008 Premium
  • Windows Small Business Server 2011 Standard
Keywords: 
KB2538579

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com