How to change home directory in Active Directory using VBS

Asked By 10 points N/A Posted on -
qa-featured

Hello experts

How do I change the path of all my client’s home directory in Active Directory using a VBS logon draft? Has anybody done that before? What are the steps and how do I start?

Please help. Thanks a lot.

SHARE
Answered By 10 points N/A #102596

How to change home directory in Active Directory using VBS

qa-featured

 

Change Home Directory
 
A VBScript script in the Active Directory category.
 
Use this script to go through all users and change their home directory. There is a filter string so it will only change those home directories you want changed:
 
 
 
strNewPath: the full UNC of the new directory path (the script will automatically add the users username to the end
strSearchContext: script will scan the current home directory and if it finds a match to this string it will make the change.
Blank home directories are left untouched.
 
Source Code
Important Note: This script has not been checked by Spice works. Please understand the risks before using it.
——————————————————————————————————————————-
 
1.strNewPath          = "\sclsusers"
2.strSearchContext  = "\dx-file1"
3.
4.
5.
6.Dim rootDSE, domainObject
7.Set rootDSE = GetObject("LDAP://RootDSE")
8.domainContainer = rootDSE.Get("defaultNamingContext")
9.Set domainObject = GetObject("LDAP://" & domainContainer)
10.
11.Set fs = CreateObject ("Scripting.FileSystemObject")
12.Set logFile = fs.CreateTextFile (".ChgHomeDir.log")
13.
14.const crlf="<BR>"
15.Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
16.objExplorer.Navigate "about:blank"   
17.objExplorer.ToolBar = 0
18.objExplorer.StatusBar = 0
19.objExplorer.Width = 500
20.objExplorer.Height = 300 
21.objExplorer.Left = 100
22.objExplorer.Top = 100
23.
24.Do While (objExplorer.Busy)
25.   Wscript.Sleep 200
26.Loop
27.
28.objExplorer.Visible = 1    
29.txtOutput=""
30.
31.
32.If Right(strNewPath, 1) <> "" then
33.   strNewPath = strNewPath & ""
34.End If
35.strSearchContext = UCase(strSearchContext)
36.
37.exportUsers(domainObject)
38.
39.
40.Set oDomain = Nothing
41.showText("FINISHED!!")
42.WScript.Quit
43.
44.
45.
46.Sub ExportUsers(oObject)
47.  Dim oUser
48.   For Each oUser in oObject
49.     Select Case oUser.Class
50.        Case "user"
51.            If oUser.homeDirectory <> "" and InStr(UCase(oUser.homeDirectory), strSearchContext) > 0 then
52.               showText(oUser.displayName)
53.               logFile.WriteLine oUser.homeDirectory & "," & strNewPath & oUser.sAMaccountName
54.               oUser.Put "homeDirectory", strNewPath & oUser.sAMaccountName  
55.               oUser.SetInfo
56.            End if
57.         Case "organizationalUnit" , "container"
58.            ExportUsers(oUser)
59.      End select
60.   Next
61. End Sub
62.
63.
64.Sub ShowText(txtInput)
65.   txtOutput = "Change Home Directory Path" & crlf
66.  txtOutput = txtOutput & "==========================" & crlf & crlf
67.   txtOutput = txtOutput & "Search Context: " & strSearchContext & crlf
68.   txtOutput = txtOutput & "New Home Dir Path: " & strNewPath & crlf & crlf
69.   txtOutput = txtOutput & "Working on:  " & txtInput
70.   objExplorer.Document.Body.InnerHTML = txtOutput
71.End Sub
 
Thanks

Login/Register to Answer

Related Questions