Link to home
Start Free TrialLog in
Avatar of stayingdusty
stayingdusty

asked on

Deleting Old Profiles

I have peiced together some script from various resources to try to accomplish this goal:

I want a script that will delete all local user profiles over 6 months old, except ones with the names:
            "Administrator"
            "All Users"
            "nvconfig"
            "OtherExamples"

Here is the Code I currently have, please help me figure out what I am doing wrong.

'=================================================================

Const LocalDocumentsFolder = "C:\Documents and Settings\"

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

on error resume next

for each fldr in profolder
      if not isexception(fldr.name) AND DateDiff("D", profolder.DateLastModified, Now) < 180 Then
                  'objFSO.DeleteFolder fldr.path, True
                  wscript.echo "Deleted Folder: " & profolder
      end if
next

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


ASKER CERTIFIED SOLUTION
Avatar of sungenwang
sungenwang
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stayingdusty
stayingdusty

ASKER

That was fast and accurate! Thanks a ton!