?
Solved

Deleting Old Profiles

Posted on 2011-09-13
2
Medium Priority
?
376 Views
Last Modified: 2012-05-12
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
'==========================================================


0
Comment
Question by:stayingdusty
2 Comments
 
LVL 14

Accepted Solution

by:
sungenwang earned 2000 total points
ID: 36530945
This below should work. When troubleshooting, you should remove "on error resume next" so you know which line is having issues.

The issue was this line:
      if not isexception(fldr.name) AND DateDiff("d", fldr.DateLastModified, Now) > 180 Then

where you should use fldr.DateLastModified instead of profolder.DateLastModified

sew

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

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", fldr.DateLastModified, Now) > 180 Then
                  'objFSO.DeleteFolder fldr.path, True
                  wscript.echo "Deleted Folder: " & fldr.path
      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
'==========================================================

Open in new window

0
 

Author Closing Comment

by:stayingdusty
ID: 36531178
That was fast and accurate! Thanks a ton!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Simple Linear Regression

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question