How Can I Change the Location of a User’s Home Drive in Active Directory?

How Can I Change the Location of a User’s Home Drive in Active Directory?

  • Comments 4
  • Likes
Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I change the location of a user’s home drive in Active Directory?

-- DS

SpacerHey, Scripting Guy! AnswerScript Center

Hey, DS. Did you ever read the story The Tell-Tale Heart by Edgar Allan Poe? In that story the narrator commits the perfect crime: he kills an old man and then dismembers and hides the body, taking such care that no one could possibly know that a murder had taken place. In the end, however, the murderer is done in by his own guilt. Believing that he still could hear the dead man’s heart beating from beneath the floorboards, he confesses to the crime: “I admit the deed!--tear up the planks!--here, here!--it is the beating of his hideous heart!"

To tell you the truth, DS, your question is sort of the tell-tale heart of the scripting world: it brings back terrible memories of one of the first scripts we posted in the Script Center, a script that changed user profile information in Active Directory. As luck would have it, somewhere along the way we dropped a colon from the drive letter (making it drive X rather than drive X:). That doesn’t seem like that big of a deal: after all, just edit the script and put the colon back. Unfortunately, though, back in those days we didn’t have the right to log onto TechNet and fix little problems like that. Consequently, we had to wait months before someone else could fix the problem for us, a period of time in which it seemed like every single person who visited the Script Center would write to us and say, “Hey, I tried that user profile script but it didn’t work.”

OK, look: “We admit the deed!--tear up the Script Center!--here, here!--it is the beating of the missing colon!"

All right, that might be carrying this a bit too far. But it still bugged us that we had posted a script that didn’t work and then couldn’t get the problem corrected.

By contrast, here is a script that should work. This script changes both the location of the home drive (the homeDirectory attribute) as well as the drive letter for the home drive (homeDrive). If all you want to do is remap the drive (that is, make the homeDrive drive X: rather than, say, drive Q:) then just leave out the line of code that assigns a value to homeDirectory:

Set objUser = GetObject("LDAP://cn=Ken Myer,ou=finance,dc=fabrikam,dc=com")
 
objUser.Put "homeDirectory", "\\atl-fs-01\users\kenmyer"
objUser.Put "homeDrive", "X:"

objUser.SetInfo

Yes, it is pretty easy, which is one reason why it drove us so crazy when it didn’t work before. (After all, it’s one thing if a 40,000 line script has a problem, but a four-line script?) We begin by binding to the Ken Myer user account in Active Directory, then use these two lines of code to specify the UNC path for the homeDirectory attribute and the drive letter (actually, the drive letter and colon) for the homeDrive:

objUser.Put "homeDirectory", "\\atl-fs-01\users\kenmyer"
objUser.Put "homeDrive", "X:"

And then we call the SetInfo method to save the changes and write the new values to the actual user account in Active Directory.

And now that our horrible secret is out, well, maybe we can pick up the pieces of our shattered lives and try to move on. In The Tell-Tale Heart the narrator was arrested and thrown in jail for his crime; you don’t think they’d do that to us just for leaving a colon out of a script, do you?

Wow; that’s harsh.


Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • How can I do this for bulk users. I have a text file that I want to reference

  • Any way you can read all the users in ad into an enum or array and loop through it until every user has a home directory? Does this script also create a folder for the user or do I have to create a folder for the users? (windows server 2003)

  • We are in the midst of doing this, we lack of a scripter in our small department, I would also like to know if there is a way to do this in bulk

  • I had a laptop with Linux on it.  My daughter needed it for personal use and her husband reformatted and put XP on it but he made the use HER name and not mine.

    When I got it back, I can use it, but all the paths and filename ownerships are her name (c:\\my documents\Jane\......

    Without having to create a new user, is there somewhere that I can change the JANE to Jerry? (registry, control panel).

    In the control panel we changed the name, but the files and paths are still in her name.