Script to delete any Drive:\smspkg\*.pck files of the specified file age

Posted on Updated on

There are many scripts and examples out there for cleaning up PCK files.  The below script is my rendition to cleanup PCK files that are older than the specified number of days.  This script can be executed via a package in ConfigMgr on systems that are a DP.  Oh and I added some basic logging to the script as well :-)


' Script to delete any Drive:\smspkg\*.pck files of the specified file age
sLogFile = "c:\windows\temp\dp_pck_cleanup.log"
iFileAge = 365

Set oFSO = CreateObject ("Scripting.FileSystemObject") 
Set oOutputFile = oFSO.OpenTextFile (sLogFile, 8, True) 
Set oWMI = GetObject("winmgmts:\\.") 
Set colItems = oWMI.ExecQuery("SELECT * FROM Win32_LogicalDisk") 

oOutputFile.WriteLine "******** PCK cleanup began ********  " & Date

For Each oDrive in colItems 
	sDrive=left(oDrive.caption,1) 
	'wscript.echo "sDrive: " & sDrive
	If (oFSO.FolderExists(sDrive & ":\smspkg\")) Then    
		oOutputFile.WriteLine "Smspkg exists on drive " & sDrive
		Set receive = oFSO.GetFolder(sDrive & ":\smspkg\") 
		Set colFiles = receive.Files 
		
		For Each oFile in colFiles 
			sFileName=(lcase(oFile))
			'wscript.echo sFileName
			If (right(sFileName, 4) = ".pck") then 
				'wscript.echo "This is a PCK file"
				If DateDiff("d", oFile.DateLastModified, Date) > iFileAge Then 
					oOutputFile.WriteLine oFile & " exists with modified date: " & oFile.DateLastModified & ", Size (MB):" & vbtab & int(oFile.Size/1048576) 
					oFSO.DeleteFile oFile,TRUE 
					oOutputFile.WriteLine "      Deleted successfully "
				End If 
			End If 
		Next 
	Else
		oOutputFile.WriteLine "No smspkg folder on " & sDrive
	End If 
Next 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s