+ Post New Thread
Results 1 to 5 of 5
Windows Thread, Script to delete all local user accounts in Technical; hi, Has anyone got a script that deletes all local user accounts, except ones I specify such as the administrator ...
  1. #1

    Join Date
    Jun 2010
    Location
    England
    Posts
    554
    Thank Post
    65
    Thanked 31 Times in 29 Posts
    Rep Power
    24

    Script to delete all local user accounts

    hi,
    Has anyone got a script that deletes all local user accounts, except ones I specify such as the administrator account and service accounts and also enables and sets a password for the local admin account.
    Its for windows7.

    Thanks

  2. IDG Tech News

  3. #2
    ricki's Avatar
    Join Date
    Jul 2005
    Location
    uk
    Posts
    1,206
    Thank Post
    19
    Thanked 129 Times in 125 Posts
    Rep Power
    41
    Have a see if this will do what you want How to Add domain accounts to Local Administrators Group using GPO - Richard&#39s myITforum Blog

    Richard

  4. #3

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    11,848
    Blog Entries
    6
    Thank Post
    592
    Thanked 1,044 Times in 921 Posts
    Rep Power
    224
    Are you using Server 2008 R2? You can do this in group policy preferences

  5. #4
    Gibbo's Avatar
    Join Date
    Feb 2008
    Location
    Cheshire
    Posts
    1,895
    Thank Post
    143
    Thanked 294 Times in 196 Posts
    Rep Power
    78
    I have this batch file:

    Code:
    @echo off
    c:
    cd\
    cd "c:\Documents and Settings\"
    dir *.* /b /o:d > \dirs.txt
    for /f "tokens=*" %%a in (\dirs.txt) do call :DelFiles "%%a"
    del \dirs.txt
    exit /b
    
    :DelFiles %1
    set Flag=0
    if %1=="All Users" set Flag=1
    if %1=="Administrator" set Flag=1
    if "%Flag%"=="0" (
    cd %1
    attrib *.* -r /s
    cd..
    rem change rd %1 /s /q
    rem for no confirmation
    rd %1 /s /q
    )
    or a nice VB script:

    Code:
    On Error Resume Next
    	 Dim obtainfolder
    	 Dim Pathfinder
    	 Dim strPath
    
    	 Set fso = CreateObject("Scripting.FileSystemObject")
    
    	 strPath = "C:\Documents and Settings\"
    	 
    	 userexcludelist = "Administrator,All Users,Default User,localservice,networkservice,"
    	
    	 Set f = fso.GetFolder(strPath)
    
    	 ' Loop through all subfolders
    	 For Each fldrItem in f.SubFolders
    	   fldrName = fldrItem.name
    	   If Right(strPath,1) <> "\" Then
    	     Pathfinder = strPath & "\" & fldrName
    	   Else
    	     Pathfinder = strPath & fldrName
    	   End If
    
    	   If InStr(1, ".00", fldrName, 1) Then
    	     set obtainfolder = fso.GetFolder(Pathfinder)
    	     obtainfolder.Delete true
    	   Else
                    
                    End If
    	 Next
    
    	 ' Clean up objects
    	 Set fso = Nothing
    	 Set fc = Nothing

  6. #5
    bio
    bio is offline
    bio's Avatar
    Join Date
    Apr 2008
    Location
    netherlands
    Posts
    506
    Thank Post
    16
    Thanked 126 Times in 99 Posts
    Rep Power
    33
    check my blog here and look for Shonks script.

    bio..

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 6
    Last Post: 26th September 2008, 03:57 PM
  2. Replies: 3
    Last Post: 18th January 2008, 02:46 PM
  3. Replies: 3
    Last Post: 25th September 2006, 12:27 PM
  4. Replies: 7
    Last Post: 27th November 2005, 11:41 PM
  5. Script to create a local user on a XP box.
    By tosca925 in forum Scripts
    Replies: 3
    Last Post: 12th October 2005, 12:04 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •