Solved

Deleting Old Profiles

Posted on 2011-09-13
2
371 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
sungenwang earned 500 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
In this post we will learn different types of Android Layout and some basics of an Android App.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

734 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