Deleting User Profiles / Temp Files

(imported topic written by SystemAdmin)

We are trying to accomplish some basic system maintenance with BigFix. We’d like to be able to do two things which are fairly easy to do in vbscript or powershell. The question we have is has anyone done it in BigFix?

Task 1: Delete User Profiles older than a specific age

We are looking to do more than just a file / folder delete. We want to removed the associated registry entries just like what would happen if you went to My Computer | System Properties | User Profiles | Settings and deleted them from there. The registry key where they are kept is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList. This is also how the resource kit DELPROF tool works, but it’s not as flexible as we need it to be.

Task 2: Delete all files in ALL temp folders on the system.

So this would include %windir%\temp, along with every %temp% path for each user profile on the machine. Normally only the currently loaded profile will have its temp files deleted. So it needs to enumerate all the profile folders under “Documents and Settings” or “Users” and clean out the files in the temp directories under there as well.

So if anyone has done something similar in BigFix and you could share it, even if it is just recursive directory functionality, I’d owe ya!

(imported comment written by donald__small91)

Were you ever able to figure this out. I too would like to schedule some automated cleanup tasks with BigFix, like deleting temp files and old profiles, as well as maybe scheduling a defrag to run after hours on PCs.

(imported comment written by SystemAdmin)

This is a great non-BigFix solution that could probably be implemented in BigFix: http://www.theshonkproject.com/index.php?option=com_content&task=view&id=50&Itemid=31

(imported comment written by SystemAdmin)

We ended up with a vb script for the temp files and delprof for the profiles - The only problem with the vbscript is when it encounters a file it can’t delete - so we just trap for errors and move on, not the best logic and it doesn;t completely clean the temp directory, but it’s pretty good at getting most items:

Code

Set oFileSys = CreateObject(“Scripting.FileSystemObject”)

Set oWshShell = CreateObject(“WScript.Shell”)

Set oFolder = oFileSys.GetFolder(oWshShell.ExpandEnvironmentStrings("%TEMP%"))

on error resume next

For Each oFile In oFolder.files

oFileSys.DeleteFile oFile

Next

For Each oSubFolder In oFolder.SubFolders

subRecurseSubFolders (oSubFolder)

Next

Sub subRecurseSubFolders (SubPath)

oFileSys.DeleteFolder SubPath

End Sub

End Code

(imported comment written by donald__small91)

I just got this to work with deleting temp files for %windir%\temp and ALL user preofiles temp folders.

waithidden cmd.exe /C del /S /Q /F %WINDIR%\Temp*.*

delete __appendfile

delete purgeprofiletemp.bat

appendfile @ECHO OFF

appendfile for /d %%K in (“C:\Documents and Settings*”) do (del /S /F /Q “%%~fK\Local Settings\Temp*.*”)

move __appendfile purgeprofiletemp.bat

waithidden cmd.exe /C purgeprofiletemp.bat

delete purgeprofiletemp.bat

Hope this works for you.