Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - User and Home Folder Management

Reply
 
Old 11-21-2008   #1 (permalink)
bmg67


 
 

User and Home Folder Management

Hi,
Is there a way to compare user accounts with the home directory folder names?
Maybe return the result of non matching folders to a text file or better yet
move the folders to another folder that would HOLD them for my review?

Ex. user name, Smith_JohnA does not exists in AD but he does have a home
folder named \\server\home\Smith_JohnA

The home folder would then be moved to: \\server\home\Hold\Smith_JohnA

Thanks for your help in advance!

Mike



My System SpecsSystem Spec
Old 11-22-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: User and Home Folder Management

Mike wrote:
Quote:

> Is there a way to compare user accounts with the home directory folder
> names?
> Maybe return the result of non matching folders to a text file or better
> yet
> move the folders to another folder that would HOLD them for my review?
>
> Ex. user name, Smith_JohnA does not exists in AD but he does have a home
> folder named \\server\home\Smith_JohnA
>
> The home folder would then be moved to: \\server\home\Hold\Smith_JohnA
>
> Thanks for your help in advance!
A similar question was asked about a month ago. I suggested the script
below. Note that the folder name need not match the username, but it must be
assigned on the Profile tab of ADUC.
===========
Option Explicit

Dim objRootDSE, strDNSDomain, adoCommand, adoConnection
Dim strBase, strFilter, strAttributes, strQuery, adoRecordset
Dim strHomeDir
Dim objFSO, strUsersFolder, objUsersFolder, objFolder
Dim objList, strDir, strTarget

' Specify where unused home folders will be moved.
' This folder must exist.
strTarget = "\\Server\home\hold"

' Create dictionary object to track home folders.
Set objList = CreateObject("Scripting.Dictionary")
objList.CompareMode = vbTextCompare

' Add all subfolders of share to dictionary object.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUsersFolder = "\\Server\home"
Set objUsersFolder = objFSO.GetFolder(strUsersFolder)
For each objFolder In objUsersFolder.SubFolders
' Key value is the full folder path,
' item value is the folder name.
objList(objFolder.Path) = objFolder.Name
Next

' Determine DNS domain name.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"

' Search for all users with home directories.
strFilter = "(&(objectCategory=person)(objectClass=user)" _
& "(homeDirectory=*))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "homeDirectory"

' Construct the LDAP query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values.
strHomeDir = adoRecordset.Fields("homeDirectory").Value
If (objList.Exists(strHomeDir) = True) Then
' This folder is assigned as home directory to a user.
' Flag as used by blanking out the folder name.
objList(strHomeDir) = ""
End If
adoRecordset.MoveNext
Loop

' Enumerate home directories in the share.
For Each strDir In objList.Keys
' Check if assigned to a user.
If (objList(strDir) <> "") Then
' This folder is not assigned.
' Move the folder.
objFSO.MoveFolder strDir, strTarget & "\" & objList(strDir)
End If
Next

' Clean up.
adoRecordset.Close
adoConnection.Close

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 11-24-2008   #3 (permalink)
bmg67


 
 

Re: User and Home Folder Management

Richard thanks for the speedy reply.
Would you please direct me to the other request so that I can be sure that I
am not missing something.

ran the script on my DC and get the following message:
line: 76
char: 9
Error: Invalid procedure call or argument
code: 800A0005


"Richard Mueller [MVP]" wrote:
Quote:

> Mike wrote:
>
Quote:

> > Is there a way to compare user accounts with the home directory folder
> > names?
> > Maybe return the result of non matching folders to a text file or better
> > yet
> > move the folders to another folder that would HOLD them for my review?
> >
> > Ex. user name, Smith_JohnA does not exists in AD but he does have a home
> > folder named \\server\home\Smith_JohnA
> >
> > The home folder would then be moved to: \\server\home\Hold\Smith_JohnA
> >
> > Thanks for your help in advance!
>
> A similar question was asked about a month ago. I suggested the script
> below. Note that the folder name need not match the username, but it must be
> assigned on the Profile tab of ADUC.
> ===========
> Option Explicit
>
> Dim objRootDSE, strDNSDomain, adoCommand, adoConnection
> Dim strBase, strFilter, strAttributes, strQuery, adoRecordset
> Dim strHomeDir
> Dim objFSO, strUsersFolder, objUsersFolder, objFolder
> Dim objList, strDir, strTarget
>
> ' Specify where unused home folders will be moved.
> ' This folder must exist.
> strTarget = "\\Server\home\hold"
>
> ' Create dictionary object to track home folders.
> Set objList = CreateObject("Scripting.Dictionary")
> objList.CompareMode = vbTextCompare
>
> ' Add all subfolders of share to dictionary object.
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> strUsersFolder = "\\Server\home"
> Set objUsersFolder = objFSO.GetFolder(strUsersFolder)
> For each objFolder In objUsersFolder.SubFolders
> ' Key value is the full folder path,
> ' item value is the folder name.
> objList(objFolder.Path) = objFolder.Name
> Next
>
> ' Determine DNS domain name.
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDNSDomain = objRootDSE.Get("defaultNamingContext")
>
> ' Use ADO to search Active Directory.
> Set adoCommand = CreateObject("ADODB.Command")
> Set adoConnection = CreateObject("ADODB.Connection")
> adoConnection.Provider = "ADsDSOObject"
> adoConnection.Open "Active Directory Provider"
> adoCommand.ActiveConnection = adoConnection
>
> ' Search entire domain.
> strBase = "<LDAP://" & strDNSDomain & ">"
>
> ' Search for all users with home directories.
> strFilter = "(&(objectCategory=person)(objectClass=user)" _
> & "(homeDirectory=*))"
>
> ' Comma delimited list of attribute values to retrieve.
> strAttributes = "homeDirectory"
>
> ' Construct the LDAP query.
> strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
>
> ' Run the query.
> adoCommand.CommandText = strQuery
> adoCommand.Properties("Page Size") = 100
> adoCommand.Properties("Timeout") = 30
> adoCommand.Properties("Cache Results") = False
> Set adoRecordset = adoCommand.Execute
>
> ' Enumerate the resulting recordset.
> Do Until adoRecordset.EOF
> ' Retrieve values.
> strHomeDir = adoRecordset.Fields("homeDirectory").Value
> If (objList.Exists(strHomeDir) = True) Then
> ' This folder is assigned as home directory to a user.
> ' Flag as used by blanking out the folder name.
> objList(strHomeDir) = ""
> End If
> adoRecordset.MoveNext
> Loop
>
> ' Enumerate home directories in the share.
> For Each strDir In objList.Keys
> ' Check if assigned to a user.
> If (objList(strDir) <> "") Then
> ' This folder is not assigned.
> ' Move the folder.
> objFSO.MoveFolder strDir, strTarget & "\" & objList(strDir)
> End If
> Next
>
> ' Clean up.
> adoRecordset.Close
> adoConnection.Close
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>
My System SpecsSystem Spec
Old 11-24-2008   #4 (permalink)
bmg67


 
 

Re: User and Home Folder Management

Richard,
I must clarify, I am trying to query AD for the sAMAccountName. This is the
logon account and the folder name.

Ex. John A. Smith has a user name of "smith_johna" and folder name
"smith_johna"

So, I am looking for a way to compare the names in AD to the folders on my
file server. That will move any folders that do not have a matching domain
account.

We do not have the user profiles set up map the home folder (Yet), that is a
work in progress for me. I am still working to consolidate the many user
shares on multiple servers. We only need two share locations....

Thanks again for your help.
My System SpecsSystem Spec
Old 11-24-2008   #5 (permalink)
Richard Mueller [MVP]


 
 

Re: User and Home Folder Management


"bmg67" <bmg67@xxxxxx> wrote in message
news:2378ECF0-77AE-43AC-8FA0-1E0F41D50EB0@xxxxxx
Quote:

> Richard,
> I must clarify, I am trying to query AD for the sAMAccountName. This is
> the
> logon account and the folder name.
>
> Ex. John A. Smith has a user name of "smith_johna" and folder name
> "smith_johna"
>
> So, I am looking for a way to compare the names in AD to the folders on my
> file server. That will move any folders that do not have a matching domain
> account.
>
> We do not have the user profiles set up map the home folder (Yet), that is
> a
> work in progress for me. I am still working to consolidate the many user
> shares on multiple servers. We only need two share locations....
>
> Thanks again for your help.
I still would use ADO to retrieve the sAMAccountName's of all users and
compare with the folder names. I also would still use a dictionary object to
keep track of the folders. However, since we are comparing the name of the
folder with the username (rather than the full path with the homeDirectory
value), we need to reverse the key and item values in the dictionary object.
The name of the folder must be the key value, which means that there cannot
be any duplicates. The folder path will be the item value. The script could
be similar to below:
============
Option Explicit

Dim objRootDSE, strDNSDomain, adoCommand, adoConnection
Dim strBase, strFilter, strAttributes, strQuery, adoRecordset
Dim strNTName
Dim objFSO, strUsersFolder, objUsersFolder, objFolder
Dim objList, strUser, strTarget

' Specify where unused folders will be moved.
' This folder must exist.
strTarget = "\\Server\home\hold"

' Create dictionary object to track folders.
Set objList = CreateObject("Scripting.Dictionary")
objList.CompareMode = vbTextCompare

' Add all subfolders of share to dictionary object.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUsersFolder = "\\Server\home"
Set objUsersFolder = objFSO.GetFolder(strUsersFolder)
For each objFolder In objUsersFolder.SubFolders
' Key value is the folder name (also the user name).
' Item value is the full folder path.
objList(objFolder.Name) = objFolder.Path
Next

' Determine DNS domain name.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"

' Search for all users.
strFilter = "(&(objectCategory=person)(objectClass=user))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName"

' Construct the LDAP query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values.
strNTName = adoRecordset.Fields("sAMAccountName").Value
If (objList.Exists(strNTName) = True) Then
' This folder is assigned to a user.
' Flag as used by blanking out the folder path.
objList(strNTName) = ""
End If
adoRecordset.MoveNext
Loop

' Enumerate folder names (key values).
' These are also user names.
For Each strUser In objList.Keys
' Check if assigned to a user.
If (objList(strUser) <> "") Then
' This folder is not assigned to a user.
' Move the folder.
objFSO.MoveFolder objList(strUser), strTarget & "\" & strUser
End If
Next
==========
I haven't tested, but I think I got the code right. You can first run the
script with the MoveFolder statement commented out and add a statement that
echos the MoveFolder statement to make sure it looks correct. For example:
==========
' Enumerate folder names (key values).
' These are also user names.
For Each strUser In objList.Keys
' Check if assigned to a user.
If (objList(strUser) <> "") Then
' This folder is not assigned to a user.
' Echo the MoveFolder statement (for troubleshooting).
Wscript.Echo "objFSO.MoveFolder " & objList(strUser) & ", " &
strTarget & "\" & strUser
End If
Next

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 11-25-2008   #6 (permalink)
bmg67


 
 

Re: User and Home Folder Management

Richard,
This is what actually worked for me (Thanks so very much for your help):
Option Explicit

Dim objRootDSE, strDNSDomain, adoCommand, adoConnection
Dim strBase, strFilter, strAttributes, strQuery, adoRecordset
Dim strNTName
Dim objFSO, strUsersFolder, objUsersFolder, objFolder
Dim objList, strUser, strTarget

' Specify where unused folders will be moved.
' This folder must exist.
strTarget = "d:\Hold"


' Create dictionary object to track folders.
Set objList = CreateObject("Scripting.Dictionary")
objList.CompareMode = vbTextCompare

' Add all subfolders of share to dictionary object.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUsersFolder = "d:\users"

Set objUsersFolder = objFSO.GetFolder(strUsersFolder)
For each objFolder In objUsersFolder.SubFolders
' Key value is the folder name (also the user name).
' Item value is the full folder path.
objList(objFolder.Name) = objFolder.Path
Next

' Determine DNS domain name.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"

' Search for all users.
strFilter = "(&(objectCategory=person)(objectClass=user))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName"

' Construct the LDAP query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values.
strNTName = adoRecordset.Fields("sAMAccountName").Value
If (objList.Exists(strNTName) = True) Then
' This folder is assigned to a user.
' Flag as used by blanking out the folder path.
objList(strNTName) = ""
End If
adoRecordset.MoveNext

Loop

'Enumerate folder names (key values).
' These are also user names.
For Each strUser In objList.Keys
' Check if assigned to a user.
If (objList(strUser) <> "") Then
' This folder is not assigned to a user.
' Echo the MoveFolder statement (for troubleshooting).
'Wscript.Echo "objFSO.MoveFolder" & objList(strUser), strTarget &
"\" & strUser
objFSO.MoveFolder objList(strUser), strTarget & "\" & strUser
End If
Next

'Clean up
adoRecordset.Close
adoConnection.Close
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Folder management in the User areas Vista General
Folder Management Vista mail
Management memory at Vista Home Premium 32 bits Vista General
Guest User Management Vista account administration
Public/Music Folder Management Vista music pictures video


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46