{"id":68413,"date":"2005-12-02T19:45:00","date_gmt":"2005-12-02T19:45:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/12\/02\/how-can-i-change-the-location-of-a-users-home-drive-in-active-directory\/"},"modified":"2005-12-02T19:45:00","modified_gmt":"2005-12-02T19:45:00","slug":"how-can-i-change-the-location-of-a-users-home-drive-in-active-directory","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-change-the-location-of-a-users-home-drive-in-active-directory\/","title":{"rendered":"How Can I Change the Location of a User\u2019s Home Drive in Active Directory?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! How can I change the location of a user\u2019s home drive in Active Directory?<BR><BR>&#8212; DS<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/A> \n<P>Hey, DS. Did you ever read the story <I>The Tell-Tale Heart<\/I> 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\u2019s heart beating from beneath the floorboards, he confesses to the crime: \u201cI admit the deed!&#8211;tear up the planks!&#8211;here, here!&#8211;it is the beating of his hideous heart!&#8221;<\/P>\n<P>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 <B>X<\/B> rather than drive <B>X:<\/B>). That doesn\u2019t 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\u2019t have the right to log onto TechNet and fix little problems like that. Consequently, we had to wait <I>months<\/I> 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, \u201cHey, I tried that user profile script but it didn\u2019t work.\u201d <\/P>\n<P>OK, look: \u201cWe admit the deed!&#8211;tear up the Script Center!&#8211;here, here!&#8211;it is the beating of the missing colon!&#8221;<\/P>\n<P>All right, that might be carrying this a bit too far. But it still bugged us that we had posted a script that didn\u2019t work and then couldn\u2019t get the problem corrected.<\/P>\n<P>By contrast, here is a script that <I>should<\/I> work. This script changes both the location of the home drive (the <B>homeDirectory<\/B> attribute) as well as the drive letter for the home drive (<B>homeDrive<\/B>). 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: <\/P><PRE class=\"codeSample\">Set objUser = GetObject(&#8220;LDAP:\/\/cn=Ken Myer,ou=finance,dc=fabrikam,dc=com&#8221;)<\/p>\n<p>objUser.Put &#8220;homeDirectory&#8221;, &#8220;\\\\atl-fs-01\\users\\kenmyer&#8221;\nobjUser.Put &#8220;homeDrive&#8221;, &#8220;X:&#8221;<\/p>\n<p>objUser.SetInfo\n<\/PRE>\n<P>Yes, it <I>is<\/I> pretty easy, which is one reason why it drove us so crazy when it didn\u2019t work before. (After all, it\u2019s 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:<\/P><PRE class=\"codeSample\">objUser.Put &#8220;homeDirectory&#8221;, &#8220;\\\\atl-fs-01\\users\\kenmyer&#8221;\nobjUser.Put &#8220;homeDrive&#8221;, &#8220;X:&#8221;\n<\/PRE>\n<P>And then we call the <B>SetInfo<\/B> method to save the changes and write the new values to the actual user account in Active Directory. <\/P>\n<P>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 <I>The Tell-Tale Heart<\/I> the narrator was arrested and thrown in jail for his crime; you don\u2019t think they\u2019d do that to us just for leaving a colon out of a script, do you? <\/P>\n<P>Wow; that\u2019s harsh.<\/P><BR>\n<DIV>\n<TABLE class=\"\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">\n<TBODY>\n<TR>\n<TD class=\"\"><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/dec05\/hey1202.mspx#top\"><IMG height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/technet\/mnplibrary\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/A><A class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/dec05\/hey1202.mspx#top\">Top of page<\/A><\/TD><\/TR><\/TBODY><\/TABLE><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I change the location of a user\u2019s home drive in Active Directory?&#8212; DS 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 [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,9,3,4,20,5],"class_list":["post-68413","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-adsi","tag-scripting-guy","tag-scripting-techniques","tag-user-accounts","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I change the location of a user\u2019s home drive in Active Directory?&#8212; DS 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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=68413"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68413\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=68413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=68413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=68413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}