+ 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
    15

    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. #2

    Join Date
    May 2007
    Location
    Norfolk
    Posts
    157
    Thank Post
    21
    Thanked 3 Times in 3 Posts
    Rep Power
    15
    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

  3. #3
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,524
    Thank Post
    106
    Thanked 88 Times in 74 Posts
    Blog Entries
    46
    Rep Power
    40
    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

  4. Thanks to browolf from:

    reggiep (22nd April 2008)

  5. #4

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

  6. #5

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,843
    Thank Post
    876
    Thanked 1,679 Times in 1,459 Posts
    Blog Entries
    12
    Rep Power
    444
    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. Script to Delete Profiles - PLEASE HELP
    By Mr_M_Cox in forum Scripts
    Replies: 13
    Last Post: 22nd February 2013, 03:53 PM
  2. Replies: 2
    Last Post: 17th April 2008, 11:25 AM
  3. Replies: 5
    Last Post: 9th March 2008, 12:15 AM
  4. Wanted: VBScript to delete folders from C:
    By timbo343 in forum Scripts
    Replies: 7
    Last Post: 7th February 2008, 11:50 AM
  5. Replies: 15
    Last Post: 19th September 2007, 10:46 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
  •