By David Wiseman (Administrator)Created 14 Jan 2006
My Rating:
Vote
Rating:
Not Rated
Views:40915
Downloads:1749

Delete Local Profiles

Language:  VBScript

Description

Delete all the local profiles stored on a computer.(All folders stored in the "C:\Documents and Settings\" folder with a few exceptions added.)


Notes
This script could be run as a start-up or shutdown script to stop windows saving copies of user profiles. Please note that there is a group policy setting to delete cached copies of roaming profiles, and running this script might impact logon performance. Please use this script with particular caution as it has the potential to delete user documents if folder redirection is not used. 
Code

Line Numbers: On  Off      Plain Text
Const LocalDocumentsFolder = "C:\Documents and Settings\"

set objFSO = createobject("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder(localdocumentsfolder)

on error resume next

for each fldr in objFolder.SubFolders
	if not isexception(fldr.name) then
		objFSO.DeleteFolder fldr.path, True
	end if
next


Function isException(byval foldername)
	select case foldername
		case "All Users"
			isException = True
		case "Default User"
			isException = True
		case "LocalService"
			isException = True
		case "NetworkService"
			isException = True
		case "Administrator"
			isException = True
		case Else
			isException = False
	End Select
End Function

 


Got a useful script? Click here to upload!


 

  Post Comment
Order By:  
User Comments
      
topokin1
Posted On: 7/18/2008 6:45:43 AM

Would there be a way to extend the script to also check the age of the profile before deleting it. For example, that only profiles older than 1 month should be deleted.

tskrich
Posted On: 9/10/2008 12:36:18 PM

Although i do like scripts, There is a Microsoft utility that will let you to delete profiles. I use this on a regular basis.
http://www.microsoft.com/DownLoads/details.aspx?familyid=901A9B95-6063-4462-8150-360394E98E1E&displaylang=en

garish22
Posted On: 1/18/2013 12:36:51 AM

Can I use this script as it is or should change some lines? can you answer fast. I am really in need of this. Thank you, Regards, Gary