mrforgetful Posted February 11, 2008 Posted February 11, 2008 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.
srochford Posted February 11, 2008 Posted February 11, 2008 We do this - http://techinfo.cnwl.ac.uk/Windows%20Scripts/default.asp?dest=home%20folder%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 :-) 2
sidewinder Posted February 12, 2008 Posted February 12, 2008 ^ 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
srochford Posted February 13, 2008 Posted February 13, 2008 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!)
mrforgetful Posted February 18, 2008 Author Posted February 18, 2008 Would it be possible to change the script so that it output the findings to a text file / csv instead of deleting them?
Oakie Posted September 4, 2008 Posted September 4, 2008 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. '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 = " ">;(&(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 3
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now