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
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.
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:
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.
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.
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.