Home All Groups Group Topic Archive Search About

Modify user home directory path



Author
18 Oct 2007 10:15 PM
dung.t.ng
Hi All,

I'm new to the VBScripting world. I need help with a script that can
modify user home directory path. I'm going to move approximately 1500
user home directories from one server to another. I need a script that
can collect users list from a text file and modify user home directory
path in Active Directory User & Computer. Hope I don't have to modify
each user account manually.

Thanks in advance for help from scripting expert out there.

dtng

Author
19 Oct 2007 12:35 AM
Richard Mueller [MVP]
dtng wrote:

> I'm new to the VBScripting world. I need help with a script that can
> modify user home directory path. I'm going to move approximately 1500
> user home directories from one server to another. I need a script that
> can collect users list from a text file and modify user home directory
> path in Active Directory User & Computer. Hope I don't have to modify
> each user account manually.

I have an example VBScript program that updates the profilePath attribute
for users in bulk from the information in an Excel spreadsheet 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 spreadsheet 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 spreadsheet is assumed to have column headers and is
skipped.

There is also a link to a program to create the spreadsheet 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 spreadsheet) 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
    objSheet.Cells(k, 1).Value = strDN
    objSheet.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 spreadsheet, since 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 spreadsheet, work on the
spreadsheet, then run another program to update AD from the spreadsheet.
This is better than letting the program modify users in bulk with no review
of what will happen. You can also break up the spreadsheet into several,
perhaps testing first with a few users, or modifying users in one OU at a
time.

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

AddThis Social Bookmark Button