Jump to content

Recommended Posts

Posted

We run a vbscript by GPO on machine boot to delete older profiles (the date varies, from 14 days to several weeks) as we use local (no roaming) profiles across the network.

 

This doesn't seem to be working - lots of old profiles are left behind. When we run the script manually with debug messages we can see the profiles are 'selected' correctly, but a delete of one can take a long time (30 seconds or more!) and I'm guessing this might be causing the script to timeout.

 

The script is below. We leave a few local profiles alone (local ones,admins etc) Can anyone see where I'm going wrong with this?

 

When I run it directly, with the debug messages on I can see the profiles are being correctly identified as ones to delete, the delete part just seems to take ages, and the local profiles are small (<50mb)

 

I reformat the date to make sure that the dates are matched exactly, although this probably isn't necessary it does work.

 

On Error Resume Next
Dim objFSO, objWMIService, strComputer, strFilter, intMaxProfileAge, colProfiles, objProfile, dtmLastUseTime

strComputer = "."
strFilter = "SID Like ""S-1-5-21%"" And Not LocalPath Like ""%Administrator%"""

' Maximum Age of profile
intMaxProfileAge = 14

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("Winmgmts:\\" & strComputer & "\root\cimv2") 
Set colProfiles = objWMIService.ExecQuery("Select * From Win32_UserProfile Where " & strFilter)

If Not colProfiles Is Nothing Then

For Each objProfile in colProfiles
	
	dtmLastUseTime = CDate(Mid(objProfile.LastUseTime, 7, 2) & "/" & Mid(objProfile.LastUseTime, 5, 2) & "/" & Left(objProfile.LastUseTime, 4) & " " & Mid (objProfile.LastUseTime, 9, 2) & ":" & _
                                         Mid(objProfile.LastUseTime, 11,2) & ":" & Mid(objProfile.LastUseTime, 13, 2))
		

	  If DateDiff("d", dtmLastUseTime, Date) > intMaxProfileAge Then
		  Err.Clear
	          'MsgBox objprofile.localpath & " datediff= " & DateDiff("d", dtmLastUseTime, Date)
		  objProfile.Delete_
	          'msgbox err.number
  	          End If
	
Next

End If

 

Either the VB method of profile deleting is just very slow by nature, or I'm doing this the wrong way!

Posted
There's a Group Policy "Delete Profiles Older than X days" if your on Windows 7?

 

Yes, but we wanted to have a more controlled approach (like we did on XP) where for example students profiles would be removed more frequently than staff. And administrators logins would be left alone.

 

The profile worked when I tried it (IIRC, it was a while ago) but it deletes the lot as it just matches on date.

Posted

Hello

Have a look at delprof2

 

We pushed it out to all machines then a simple bat file on startup.

 

You can remotely remove profiles on any machine.

It does clear out any reg entry for the profiles as well

 

Cheers

  • Thanks 1
  • 2 months later...
Posted
Hello

We pushed it out to all machines then a simple bat file on startup.

How are you calling it? I've been working on this today, and couldn't get it to launch. I have a working batch file, but can't get it to work via GPO...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...