+ Post New Thread
Results 1 to 5 of 5
Scripts Thread, Script to delete certain folders in Coding and Web Development; Hi, I am after a script (am useless at writing them myself!) that will allow me to delete profiles that ...
  1. #1

    Join Date
    May 2007
    Location
    Norfolk
    Posts
    157
    Thank Post
    21
    Thanked 3 Times in 3 Posts
    Rep Power
    11

    Script to delete certain folders

    Hi,

    I am after a script (am useless at writing them myself!) that will allow me to delete profiles that have been created in the "C:\Documents and Settings" folder, but will leave ones that are needed (Administrator, Default User, All Users)

    Need this by Thursday (no students in due to NUT strike), and doing it automagically will be a lot easier than manually having to do it on around 300 computers

    Many Thanks

    Matt

  2. IDG Tech News

  3. #2

    Join Date
    May 2007
    Location
    Norfolk
    Posts
    157
    Thank Post
    21
    Thanked 3 Times in 3 Posts
    Rep Power
    11
    amazing what a frantic search can bring

    Got a VBS script that works now, so all is sweet. Takes a little time, but it does it

  4. #3
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,392
    Blog Entries
    41
    Thank Post
    77
    Thanked 77 Times in 64 Posts
    Rep Power
    33
    if your computers have suitably organised names, you can use delprof*

    c:\>for /f %a in ('net view ^| find "prefix" /I ') do delprof /c:%a /q /i

    replace prefix with whatever

    otherwise

    you can use

    ' The following script will enumerate all computer accounts
    ' within an Active Directory domain

    Const ADS_SCOPE_SUBTREE = 2
    strDomain = "domainname"

    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"

    Set objCOmmand.ActiveConnection = objConnection
    objCommand.CommandText = _
    "Select Name, Location from 'LDAP://" & strDomain & "' " _
    & "Where objectCategory='computer'"
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
    Set objRecordSet = objCommand.Execute
    objRecordSet.MoveFirst

    Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value
    'Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
    objRecordSet.MoveNext
    Loop
    to get a list of computers from the domain. forward it into a file ie

    c:\>cscript filename.vbs >> list.txt

    import file into excel sort and remove any u dont want to touch, laptops, servers etc

    save as a csv file

    then do

    c:\>for /f %a in ('type list.csv') do delprof /c:%a /q /i


    *deprof is specifically for deleting user profiles and will leave the other ones,
    you can download it at
    Download details: User Profile Deletion Utility (Delprof.exe)


    edit: oh you found one whilst i was writing this
    Last edited by browolf; 22nd April 2008 at 12:41 PM. Reason: updated

  5. Thanks to browolf from:

    reggiep (22nd April 2008)

  6. #4

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,117
    Blog Entries
    2
    Thank Post
    111
    Thanked 513 Times in 444 Posts
    Rep Power
    114
    Add your stuff to the machine startup script and then it will run at each startup and keep things tidy!

  7. #5

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    11,840
    Blog Entries
    6
    Thank Post
    592
    Thanked 1,043 Times in 920 Posts
    Rep Power
    224
    You can use this VBS Script

    Code:
    Function Main()
    	On Error Resume Next
    	Dim obtainfolder
    	Dim Pathfinder
    	Dim strPath
    
    	Set fso = CreateObject("Scripting.FileSystemObject")
    
    	strPath = "C:\Documents and Settings\"
    
    	set excludefile = fso.OpenTextFile("\\Server\SYSVOL\doamin.local\scripts\cleanprofiles\exclude.txt", 1)
    	excludelist = excludefile.Readall
    	'msgbox excludelist
    
    	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, excludelist, fldrName, 1) Then
    	    'msgbox "Has not deleted " & fldrName
    	  Else
    	    'msgbox "Deleting " & fldrName
    	    set obtainfolder = fso.GetFolder(Pathfinder)
    	    obtainfolder.Delete true
    	  End If
    
      'End Select
    
    	Next
    
    	' Clean up objects
    	Set fso = Nothing
    	Set fc = Nothing
    
    End Function
    
    call Main()
    make a text file and call it exclude.txt, then add the names of folders you dont want deleting such as default user & all users. Then alter the path of where it is located in the script.

    Hope this helps

    Z

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 2
    Last Post: 17th April 2008, 11:25 AM
  2. Replies: 5
    Last Post: 9th March 2008, 01:15 AM
  3. Wanted: VBScript to delete folders from C:
    By timbo343 in forum Scripts
    Replies: 7
    Last Post: 7th February 2008, 12:50 PM
  4. Replies: 15
    Last Post: 19th September 2007, 10:46 PM
  5. Script to Delete Profiles - PLEASE HELP
    By Mr_M_Cox in forum Scripts
    Replies: 10
    Last Post: 13th June 2007, 03:51 PM

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
  •