Cleanup Site Concentrator

Hey Guys,

I’ve had a number of site concentrators not clearing the cache properly.
According to,

The Site Concentrator is self-cleaning, so in 30 days or less after download, the patches, etc. will be removed from the cache path automatically.

I have not found this to be the case, so have had to write a script to do it for me.
Paremeters to be passed are:
/ConcentratorPath: for where the cache Directory is located.
/ReportOnly: if you want to see how many files are over 30 days without deleting them.

Parameter Example:
/ConcentratorPath:”c:\UpdateCache” /ReportOnly:true

Option Explicit  
Dim FSO, Folder, File, DateRange, CurrentFolder, TotalSize, FileSize, Path, bDebug, ReportOnly
Set FSO = CreateObject("Scripting.FileSystemObject") 

Path = WScript.Arguments.Named("ConcentratorPath")
ReportOnly = WScript.Arguments.Named("ReportOnly")

If FSO.FolderExists(Path) = false Then
	WScript.echo "Concentrator Path not found."
End If

If lcase(ReportOnly) = "true" Then 
	bDebug = true
	if bDebug = true Then WScript.echo "*** No Files Deleted, ReportOnly Enabled ***"
End If 

DateRange = dateadd("d", -30, Now)

If TotalSize = 0 then
	WScript.echo "No Old Updates Found."
ElseIf TotalSize > 1024 then
	TotalSize = TotalSize / 1024
	WScript.echo "Total Size: " & FormatNumber(int(TotalSize * 100) / 100, 2) & "Gb"
	WScript.echo "Total Size: " & FormatNumber(int(TotalSize * 100) / 100, 2) & "Mb"
End If

if bDebug = true Then WScript.echo "*** No Files Deleted, ReportOnly Enabled ***"

Sub ProcessDirectory(Directory)
Set CurrentFolder = FSO.GetFolder(Directory) 

For Each File in CurrentFolder.Files
	If File.DateLastModified < DateRange then
		FileSize = File.Size / 1024 / 1024
		WScript.Echo File.Name & " last modified at " & File.DateLastModified
		WScript.Echo "File Size: " & FormatNumber(int(FileSize * 100) / 100, 2) & "Mb"
		If bDebug = false Then 
			On Error Resume Next 'Dirty Error Handleing :)
			On Error goto 0
		End if
		TotalSize = TotalSize + FileSize
	End if

For Each Folder in CurrentFolder.Subfolders
	ProcessDirectory(Directory & Folder.Name)

End Sub

Leave a Reply

Your email address will not be published.