Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

active directory check and move folder

Status
Not open for further replies.

ensing

Technical User
Apr 2, 2004
10
NL
Hello,

In our environment we have a lot of user home dirs but the users are already deleted from active directory.
Can anybody help writing a script which checks the userdir and if there is a user account for that homedir? I wan't to log that in a tekst file or even rename the directory's which don't have a useraccount. The useraccounts in active directory are seperated in different OU's and subOU's
I realy don't have a clue how to do this.
Thanks in advance
 
OK, so how about you try something like this pseudo code:

Enumerate folder names

For each folder in foldername

Err= Bind to username using Winnt

If err <> 0 then
move the folder
End if


Next

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
he mark,

thanks for your reply. But I realy don't know anything about vb. So can I cut and paste this in a .vbs file?

Thx
 
No, that isn't full code.

This should do it but I have to warn that it is NOT tested. You will need to modify the DomainName and the base FolderPath before running.

Usual warnings, make sure you have a backup before you go deleting stuff, yadda yadda yadda...

Code:
'==========================================================================
'
' NAME: CompareUsersAndFolders.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 7/1/2004
'
' COMMENT: <comment>
'
'==========================================================================
On Error Resume Next
Dim FSO, FolderPath

Set FSO = CreateObject ("Scripting.FileSystemObject")
FolderPath = "D:\Shares"
DomainString = "DomainName"
Report = "Operation Completed" & vbCrLf


ShowSubFolders FSO.GetFolder(FolderPath)
MsgBox Report

Sub ShowSubFolders (FolderPath)
    For Each SubFolder In Folder.SubFolders 
    Set Err = GetObject("WinNT://" & DomainString & "/" & UserString)
        If Err <> 0 Then
        	FSO.DeleteFolder(FolderPath & "\" & SubFolder)
        	report = report & "User " & Subfolder & " does not exist.  Folder deleted." & vbCrLf
        End If
    Next

End Sub

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Ignore my post above. had a chance to do some quick testing and you should use this instead.

Code:
'==========================================================================
'
' NAME: CompareUsersAndFolders.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 7/1/2004
'
' COMMENT: <comment>
'
'==========================================================================

Dim FSO, FolderPath

Set FSO = CreateObject ("Scripting.FileSystemObject")
FolderPath = "D:\Shares"
DomainString = "DomainName"
Report = "Operation Completed" & vbCrLf


ShowSubFolders FSO.GetFolder(FolderPath)
MsgBox Report

Sub ShowSubFolders (FolderPath)
On Error Resume Next
    For Each SubFolder In FolderPath.SubFolders 
    MsgBox SubFolder.Name
    Set User = GetObject("WinNT://" & DomainString & "/" & SubFolder.Name)
        If Err <> 0 Then
        	FSO.DeleteFolder(FolderPath & "\" & SubFolder)
        	report = report & "User " & SubFolder & " does not exist.  Folder deleted." & vbCrLf
        Else
        	report = report & "User " & SubFolder & " is valid, directory not touched." & vbCrLf
        End If
    Next

End Sub

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
thx men, looks like it is working in my test environment now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top