rss

Retired Scripts: "Delete Old PerfLogs" and "Find Old Files"

I'm going to start posing old admin scripts from my personal collection. Most of my "inspiration" was from the Hey Scripting Guy! Section of the TechNet scriptcenter.

Delete old Performance Logs

Here's an old vbscript in wsf format that just cleans up Performance logs. It's most useful when scheduled with AT command.

 

deloldperf.wsf

<job>
<script language="VBScript">
'******************************************************************************
'* Delete old PerfLog Files
'* Modified: 3:29 PM 3/25/2005 -J.Bilinski
'******************************************************************************
On Error Resume Next
strComputer = "."
 
'*** Path of Log files ***
strPath = "C:\perflogs\"
 
'*** Extension of Log files ***
strExt = "blg"
 
'*** Days to keep ***
intDays = 14  
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)
Set colFiles = objFolder.Files
For Each objFile in colFiles
   If LCase(objFSO.GetExtensionName(objFile)) = strExt AND objFile.DateLastModified < date() - intDays Then
wscript.echo(objFile.Name)
      objFSO.DeleteFile(strPath & objFile.Name)
   End If
Next
 
Wscript.Quit
</script>
</job>

 

 

Find Old Files

Same idea here, but designed for searching. This one just gives you better time options and output is a text file...

findoldfiles.wsf

<job>
<script language="VBScript">
'******************************************************************************
'* Find old Files
'* Modified: 12:58 PM 11/22/2005 -J.Bilinski
'******************************************************************************
On Error Resume Next
strComputer = "."
 
'*** File to Save ***
strOutputFile = c:\oldfiles.txt
 
'*** Path to search ***
strPath = "C:\"
 
'*** Days to keep - (approximate)***
intDays = 14
intWeeks = 0
intMonths = 0
intYears = 0
 
intDays = (intYears * 365) + (intMonths * 30) + (intWeeks * 7) + intDays
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)
Set objof = fso.OpenTextFile(strOutputFile, 8, True)
Set colFiles = objFolder.Files
 
For Each objFile in colFiles
   If objFile.DateLastModified < date() - intDays Then
    
    objof.WriteLine(objFile.Name) 
    objof.Close
'//for later?//objFSO.DeleteFile(strPath & objFile.Name)//
   End If
Next
 
Wscript.Quit
</script>
</job>

 

More Script Dumps...

Bookmark


TrackBack URL: http://bilinski.org/trackback.ashx?id=24

#1 Thong on 12.17.2008 at 4:27 PM  avatar

Thanks for the sweet delete old performance logs script!

Leave a Comment

 

 (optional/private)

(optional/public)