Solved

Change HomeDirectory for all Active Directory users in a OU

Posted on 2011-02-25
8
1,011 Views
Last Modified: 2012-05-11
Hello,

I have DC 2008 Server, with Active Directory. There is a OU "Users" where all users of my domain are defined.
For the users HomeDirectory there is :

"\\fileserver01\users\firstname.lastname".

The problem is I want to modify the HomeDirectory for all users with this :

"\\fileserver02\users\%username%".

How can I change for all users with a vbs. script ?

Thanks for your help.
0
Comment
Question by:croustimiel
8 Comments
 
LVL 74

Expert Comment

by:Glen Knight
ID: 34983171
Do you actually need to do it with a Vb Script?
you can actually just bulk select the users in Active Directory users and computers and then right click properties.

You can enter the variable in there and it will update all users.

Alternatively you can use ADModify: http://admodify.codeplex.com/
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 34983207
Another question, Is it just the attribute you need changed or do you also need to change the folder name?
0
 

Author Comment

by:croustimiel
ID: 34986169
I have 200 users, i don't want to make right click > prpperties on each users......
That's the reason why i ask a script.
0
 
LVL 74

Accepted Solution

by:
Glen Knight earned 500 total points
ID: 34986233
You don't need to right click each user, you can select them all (click the. Fist one, then press and hold the sift button, then click the last one) and then right click and select properties.

Enter the veritable and this will change all of them.

Vie done it literally hundreds of times.

Also ADModify will help with this kind of task
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

Author Comment

by:croustimiel
ID: 34986299
If I select all and just change the Homedirectory, the LogonScript specified in the same properties tab will be unchanged, because it is different for each users ???
0
 
LVL 74

Expert Comment

by:Glen Knight
ID: 34986308
Only the properties you change will be applied
0
 
LVL 74

Expert Comment

by:Glen Knight
ID: 34986311
Try it on 2 or 3 if you are unsure.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 34993157
Hi, this script should do the job for you as well.  For testing purposes, make sure you comment out these lines:

      Set objUser = GetObject(adoRecordset.Fields("adsPath").Value)
      objUser.homeDirectory = strNewHomeDirectory & strUserName
      objUser.SetInfo
      Set objUser = Nothing


by putting an apostrophe in front of each line.  This will prevent any changing of the user accounts, while still reporting on them.

Regards,

Rob.
strOutputfile = "Users_HomeDirectoryChange.csv"

If Right(LCase(WScript.FullName), 11) = "wscript.exe" Then
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run "cmd /k cscript """ & WScript.ScriptFullName & """", 1, False
	Set objShell = Nothing
	WScript.Quit
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

 ' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

strDetails = """User Name"",""Full Name"",""AdsPath"",""Old Home Directory"",""New Home Directory"""

strOldHomeDirectory = "\\fileserver01\users\"
strNewHomeDirectory = "\\fileserver02\users\"
strFilter = "(&(objectCategory=person)(objectClass=user)(homeDirectory=" & Replace(strOldHomeDirectory, "\", "\5c") & "*))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "samAccountName,cn,adsPath,homeDirectory"

' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

' Run the query.
Set adoRecordset = adoCommand.Execute
 
' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
    ' Retrieve values and display.
	strUserName = adoRecordset.Fields("samAccountName").Value
	If strUserName = "rsampson" Then
	strFullName = adoRecordset.Fields("cn").Value
	strOUPath = Replace(adoRecordset.Fields("adsPath").Value, "LDAP://CN=" & strFullName & ",", "")
	strOldHomeDirectory = adoRecordset.Fields("homeDirectory").Value
	WScript.Echo "Processing " & strFullName
	Set objUser = GetObject(adoRecordset.Fields("adsPath").Value)
	objUser.homeDirectory = strNewHomeDirectory & strUserName
	objUser.SetInfo
	Set objUser = Nothing
	strDetails = strDetails & VbCrLf &_
		"""" & strUserName & """" &_
		",""" & strFullName & """" &_
		",""" & strOUPath & """" &_
		",""" & strOldHomeDirectory & """" &_
		",""" & strNewHomeDirectory & strUserName & """"
	End If
    ' Move to the next record in the recordset.
    adoRecordset.MoveNext
Loop

' Clean up.
adoRecordset.Close
Set adoRecordset = Nothing

adoConnection.Close

Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing

WScript.Echo "Done. Please see " & strOutputFile
MsgBox "Done. Please see " & strOutputFile

Open in new window

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

[b]Ok so now I will show you how to add a user name to the description at login. [/b] First connect to your DC (Domain Controller / Active Directory Server) SET PERMISSIONS FOR SCRIPT TO UPDATE COMPUTER DESCRIPTION TO USERNAME 1. Open Active …
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now