+ Post New Thread
Results 1 to 6 of 6
Windows Thread, Find Orphan User Areas in Technical; Is there a way or a program that will look through my folders containing the User Areas of people, and ...
  1. #1
    mrforgetful's Avatar
    Join Date
    May 2006
    Posts
    1,634
    Thank Post
    7
    Thanked 15 Times in 15 Posts
    Rep Power
    22

    Find Orphan User Areas

    Is there a way or a program that will look through my folders containing the User Areas of people, and look up in Active Directory to see if there's an account associated with it?

    Long shot I know.

    Just I know that when accounts are deleted from AD the User Area remains, and although we all try to remember to delete I imagine there'll be a couple somewhere.

  2. #2

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,144
    Thank Post
    113
    Thanked 518 Times in 447 Posts
    Blog Entries
    2
    Rep Power
    121
    We do this - http://techinfo.cnwl.ac.uk/Windows%2...20tidy%201.htm is my script

    Basically, it looks at each folder in the home share and checks to see if it belongs to a user as a home directory.

    the other thing we do is to check the owner of the folder - script here to do that.

    Give me a shout if that doesn't make sense :-)

  3. Thanks to srochford from:

    Andyhall (11th February 2008)

  4. #3

    Join Date
    Jul 2006
    Location
    London
    Posts
    2,962
    Thank Post
    159
    Thanked 152 Times in 116 Posts
    Rep Power
    48
    ^ that looks good..but does it just go ahead and delete any that arnt a home directory or just notify you which folders arent? Because there may be a few folders that because people have left, need to be saved somewhere else, not just deleted

    Though it is all backed up I suppose

  5. #4

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,144
    Thank Post
    113
    Thanked 518 Times in 447 Posts
    Blog Entries
    2
    Rep Power
    121
    The first script deletes - it's a bit high risk if you have admins who put folders in random places (eg d:\whome should only have user home folders in there. If someone thinks "oh, that's a good place for my temp stuff" and bungs it in there then it will get lost). Wouldn't be hard to change the delete to a move so that you just move stuff to an archive location and then do a manual check (or wait for screams; no screams means it's safe to go!)

  6. #5
    mrforgetful's Avatar
    Join Date
    May 2006
    Posts
    1,634
    Thank Post
    7
    Thanked 15 Times in 15 Posts
    Rep Power
    22
    Would it be possible to change the script so that it output the findings to a text file / csv instead of deleting them?

  7. #6

    Join Date
    Mar 2007
    Location
    Sunny Southern California
    Posts
    60
    Thank Post
    2
    Thanked 24 Times in 9 Posts
    Rep Power
    19
    Quote Originally Posted by mrforgetful View Post
    Would it be possible to change the script so that it output the findings to a text file / csv instead of deleting them?
    Here's one I use to do that. Just copy and paste into notepad and change extension to .vbs and run it.

    Code:
    'Created by Matthew Hull on 11/06/03 
    'Last Updated 12/29/03 
    'Documented on 4/25/04
    
    'Version 1.01
    
    'This script will look for orphaned folders.
    
    'Version History
    '~~~~~~~~~~~~~~~
    'Version 1.01 - The script now searchs the whole domain for the   
    
    'Version 1.0 - First version of this script released.
    '*************************************************************************************
    
    Option Explicit
    
    On Error Resume Next
    
    Dim objFSO, strUser, strRootPath, strPath, intCount, strMessage
    Dim objFolder, objRootFolder, colFolders, bolCheck, txtOutput, strOutputFile
    Dim objConnection, objCommand, objRootDSE, objRecordSet
    
    '*************************************************************************************
    'Set the root folder and the location of the output file
    
    strRootPath = "\\win2003\users"
    strOutputFile = "C:\Orphaned Folders Verification.txt"
    
    '*************************************************************************************
    
    'Create a RootDSE object for the domain
    Set objRootDSE = GetObject("LDAP://RootDSE")
    
    'Establish a connection to Active Directory using ActiveX Data Object
    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Open "Provider=ADSDSOObject;"
    
    'Create the command object and attach it to the connection object
    Set objCommand = CreateObject("ADODB.Command")
    objCommand.ActiveConnection = objConnection
    
    'Create the File System Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Set the orphan folder count to 0
    intCount = 0
    
    'Create a folder object that points to the root
    Set objRootFolder = objFSO.GetFolder(strRootPath)
    
    'Create a collection of folders that contain the subfolders of the root
    Set colFolders = objRootFolder.Subfolders
    
    'Start the message that will be displayed to the user
    strMessage = "The following folders are orphaned in " & strRootPath & vbCRLF
    
    For each objFolder in colFolders
    
       'objCommand defines the search base (in this case the whole domain) a filter
       '(All object of type user that match the foldername) and some attributes
       'associated with the returned objects (SamAccountName)
       objCommand.CommandText = "<LDAP://" & objRootDSE.Get("DefaultNamingContext") & _
       ">;(&(objectClass=user)(SamAccountName=" & objFolder.Name & "));SamAccountName"
       
       'Initiate the LDAP query and return results to a RecordSet object.
       Set objRecordSet = objCommand.Execute
       
       'Set the Check to false, it will turn true if a folder isn't orphaned
       bolCheck = False
       
       'Loop thru each item in the Record Set and compare it to the folder name
       'if they match then the folder is not orphaned.  There should only be one
       'item returned in the Record set so this procedure is fast.
       While Not objRecordset.EOF      
          If UCase(objFolder.Name) = UCase(objRecordset.Fields("SamAccountName")) Then
             bolCheck = True
       
          End If
          objRecordset.MoveNext
       Wend
       objRecordSet.MoveFirst
    
       'If the folder is orphaned increase the count and add the folder to the message
       If Not bolCheck Then
          intCount = intCount + 1
          strMessage = strMessage & intCount & " - " & objFolder.Name & vbCRLF
           
       End If
       
    
    Next
    
    'Close the connection to Active Directory
    objConnection.Close
    
    'Change the message if no orphaned folders are located
    If intCount = 0 Then
       strMessage = "There are no orphaned folders in " & strRootPath
    End If
    
    'Create a text file, write the message to it and close the text file
    Set txtOutput = objFSO.CreateTextFile(strOutPutFile)
    txtOutput.Write strMessage
    txtOutput.Close
    
    'Display a message to the user when complete
    MsgBox strMessage,vbOkOnly,"Orphan Folder Check"
    
    'Close objects
    Set objFSO = Nothing
    Set objConnection = Nothing
    Set objCommand = Nothing
    Set objRootDSE = Nothing
    Set objRecordSet = Nothing

  8. 3 Thanks to Oakie:

    alexsanger (16th February 2010), Green_Goblin (27th January 2010), rosswilson (13th December 2008)

SHARE:
+ Post New Thread

Similar Threads

  1. DPA +User Areas
    By Dos_Box in forum School ICT Policies
    Replies: 43
    Last Post: 5th December 2007, 11:54 AM
  2. User areas + User share permissions.
    By Dos_Box in forum Windows
    Replies: 6
    Last Post: 11th September 2007, 11:17 AM
  3. Copying user areas to a new Server
    By fawkers in forum Windows
    Replies: 10
    Last Post: 2nd August 2007, 10:28 AM
  4. Moving user areas (RM CC3)
    By CheeseDog in forum Wireless Networks
    Replies: 11
    Last Post: 18th September 2006, 10:42 AM
  5. User Areas - Shares!?!
    By wesleyw in forum How do you do....it?
    Replies: 7
    Last Post: 23rd August 2006, 01:07 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
  •