Question : Delete user profiles based on the age of the ntuser.dat file.

Hey folks, I am trying to delete old user profiles based on the age of the ntuser.dat file.  The quirky thing is that this is being done in a Windows 7 pre-execution boot environment.  

We use WDS to deploy our images.  When we have a Windows XP machine thats ready to be migrated to Windows 7 we have a particular boot image that when selected boots to the windows 7 pxe, automatically creates a bunch of folders, moves some stuff around, yadda yadda yadda, and it would be great if it could also look at the C:\documents and settings folder and identify all user profiles with ntuser.dat files older than.......oh say 60 days and delete those old profiles.  I can't use delprof, that won't work in W7pxe.  Any ideas?  Thanks folks.

Answer : Delete user profiles based on the age of the ntuser.dat file.

This should do the trick.  Let me know what you think.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
intMaxAge = 60

'Create Objects
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Get special folder paths
strAllUserProfile = objShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")

Set SkipProfilesArray = CreateObject("Scripting.Dictionary")
SkipProfilesArray.Add "Administrator", "Administrator"
SkipProfilesArray.Add "All Users","All Users"
SkipProfilesArray.Add "Default User","Default User"
SkipProfilesArray.Add "LocalService","LocalService"
SkipProfilesArray.Add "NetworkService","NetworkService"

strAllProfiles = objFSO.GetParentFolderName(strAllUserProfile)
Set objProfiles = objFSO.GetFolder(strAllProfiles)

For Each strUserProfile In objProfiles.SubFolders
	If Not SkipProfilesArray.Exists(strUserProfile.Name) Then
	Set objDAT = objFSO.GetFile(strUserProfile & "\NTUSER.DAT")
		If DateDiff("D", objDAT.DateLastModified, Now()) > intMaxAge Then
			objFSO.DeleteFolder strUserProfile
		End If
	End If
Next
Random Solutions  
 
programming4us programming4us