IIS Log Files cleaning Script
6:20 PMYou can run below script in IIS for cleaning the logs
***************************************************************************
Dim fso, folder, file, filecollection, dir, days_in, days_dif, filesplit
'Dim WshShell
'Set WshShell = WScript.CreateObject("WScript.Shell")
'WScript.Echo WshShell.CurrentDirectory
If ((Wscript.Arguments.Count < 3) or (Wscript.Arguments.Count > 3)) then
Wscript.echo "Script requires 3 parameters"
Wscript.echo "cscript log_clean (directory) (days) (extension)"
Wscript.echo "cscript log_clean c:\ 30 log"
Wscript.echo "(directory) is folder to delete logs out of"
Wscript.echo "(days) sets the age for a file delete, if file older then (days), it is deleted"
Wscript.echo "(extension) sets which files the tool will look at)"
Wscript.Quit 3
end if
dir = Wscript.Arguments.Item(0)
days_in = Wscript.Arguments.Item(1)
ext = Wscript.Arguments.Item(2)
set fso = CreateObject("Scripting.FileSystemObject")
set folder = fso.GetFolder(dir)
set filecollection = folder.files
For Each file in filecollection
filesplit = Split(file.name, ".")
If (Ucase(filesplit(UBound(filesplit))) = Ucase(ext)) then
days_dif = DateDiff("d", file.DateLastModified, date)
if ((cint(days_dif)) > (cint(days_in))) then
wscript.echo file.name&" is "&DateDiff("d", file.DateLastModified, date)&" days old"
wscript.echo "Will delete "&file.name
file.Delete[(force)]
else
wscript.echo file.name&" is "&DateDiff("d", file.DateLastModified, date)&" days old"
wscript.echo "Will keep "&file.name
end if
end if
Next
0 comments