Re: Update "homeDirectory" path for users?




"gscanga" <gscanga@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:63D56F22-F70D-421F-A618-CD83494A4E00@xxxxxxxxxxxxxxxx
What's the best way to replace the "homeDirectory" field for domain user
accounts? I was looking into CSVDE but can't determine if this utility is
designed for updating single account attributes. Perhaps there's a better
way?

I think this can be done with command line tools, but I have not researched
it. Instead, I have an example VBScript program that updates the profilePath
attribute
for users in bulk from the information in an Excel spread*** linked here:

http://www.rlmueller.net/UpdateUserProfile.htm

This program can be easily modified to update the homeDirectory attribute
instead. You would replace all references to "profilePath" with
"homeDirectory". The spread*** should have the user Distinguished Names in
the first column and the new value for homeDirectory in the second column.
The first row of the spread*** is assumed to have column headers and is
skipped.

There is also a link to a program to create the spread*** with the
Distinguished Names of all users in the domain:

http://www.rlmueller.net/Create%20User%20List%203.htm

For your purpose you could modify this program to also put the existing
value of the homeDirectory attribute in the second column. To do this you
would add the additional attribute to the comma delimited list of attributes
to be retrieved with the LDAP syntax ADO query. The existing query is
defined by the statement:

strQuery = "<LDAP://"; & strDNSDomain & ">;" & strFilter _
& ";distinguishedName;subtree"

You would change this to:

strQuery = "<LDAP://"; & strDNSDomain & ">;" & strFilter _
& ";distinguishedName,homeDirectory;subtree"

Then the loop that enumerates the resulting recordset (and writes values to
the spread***) would be modified as follows:
========
Dim strProfilePath
Do Until adoRecordset.EOF
strDN = adoRecordset.Fields("distinguishedName").Value
' Escape any forward slash characters, "/", with the backslash
' escape character. All other characters that should be escaped are.
strDN = Replace(strDN, "/", "\/")
strProfilePath = adoRecordset.Fields("homeDirectory").Value
obj***.Cells(k, 1).Value = strDN
obj***.Cells(k, 2).Value = strProfilePath
k = k + 1
adoRecordset.MoveNext
Loop
========
I added a statement to declare the new variable strProfilePath in a Dim
statement (since the program uses Option Explicit). It should be easy to do
a global find and replace in the spread***, if you are merely changing
the server name. You can also delete rows corresponding to users that should
not be modified.

I like using a two step process, where I create a spread***, work on the
spread***, then run another program to update AD from the spread***.
This is better than letting the program modify users in bulk with no review
of what will happen. You can also break up the spread*** into several,
perhaps testing first with a few users, or modifying users in one OU at a
time.

For more on using ADO to search AD, see this link:

http://www.rlmueller.net/ADOSearchTips.htm

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


.