Link to home
Start Free TrialLog in
Avatar of esbfern
esbfern

asked on

Mass update of AD information

We are in the process of migrating our end users from regular windows file servers which host their home directories to NetApp filers.  In all there's about 600 that will be going with the first move.  Basically what i need to do is do a query in ad that finds all users with \\servername in their AD profile as their home directory then modify that attribute with the new servername.  So for example if i have a user who's home directory is \\storm\joesmith$ i need to query for \\storm then update the attribute with \\ai-fas2\joesmith$.

I was looking through some joeware stuff using adfind and admod.  Anyone got an easy tool to do this?
Avatar of Krys_K
Krys_K
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi there

try this vbscript i wrote for you.
It search all AD for any HomeDirectory that matches what you specify and changes it to the new server you specify
There is a flag you can change to True or False which is set to make the change or just report on it

Only change the parts in teh borders

Copy this to notepad and save as a .vbs file
Open command window and type
cscript scriptname.vbs

Hope it helps

Regards
Krystian

PS i made the server names as you put in your post but check them anyway and leave the slashes in if that is how its set in the homeDirectory of you user i.e. \\storm\Home\User$
Option Explicit
 
 
	Call GetUSerInfo
 
Sub GetUSerInfo
' Version 1.0
' Written By Krystian KAria
' Dated 07-Jan-2009
 
' Gets USer details from AD
' This script gets homeDirectory
' and changes the server part of
'  all users on incorrect server
 
 
	Dim oRoot, objConnection, objCommand, objRecordSet, objUser
	Dim strBase, strQuery
	Dim strHomeDrive
	Dim strCurrentServer, strNewServer
	Dim blnChangeFlag
	
'*****************************************************************************************
	blnChangeFlag = False			'<________Change To True To make the changes rather than just report
	strCurrentServer = "\\storm\"	'<________Server you currently have it 
 	strNewServer = "\\ai-fas2\"		'<________Server you want to change it to
'*****************************************************************************************
 
' Get the Domain you are currently In
		Set oRoot = GetObject("LDAP://rootDSE")
			strBase = oRoot.Get("defaultNamingContext")
			
		Set objConnection = CreateObject("ADODB.Connection")
			objConnection.Open "Provider=ADsDSOObject;"
		
		Set objCommand = CreateObject("ADODB.Command")
			objCommand.ActiveConnection = objConnection
			
			' Clear variable ready for re-use
				strQuery = ""
				
				strQuery = strQuery & "<LDAP://" & strBase & ">;"
				strQuery = strQuery & "(&(objectClass=user)(objectCategory=person));"
				strQuery = strQuery & "sAMAccountName,DisplayName,ADsPath,homeDirectory;"
				strQuery = strQuery & "subtree"  
 
			objCommand.CommandText = strQuery
 
		Set objRecordSet = objCommand.Execute
 
' Check if any records were returned			
		If objRecordSet.RecordCount = 0  Then ' User not found in AD
			WScript.Echo "No Records Found"		
		Else
 
			Do Until objRecordset.EOF
				If Not IsNull(objRecordset.Fields("homeDirectory")) Then
					strHomeDrive = objRecordset.Fields("homeDirectory")
					WScript.Echo objRecordset.Fields("sAMAccountName") & " " & strHomeDrive
					
					If InStr(LCase(strHomeDrive), LCase(strCurrentServer)) > 0 Then 
						strHomeDrive = Replace(strHomeDrive, strCurrentServer, strNewServer)
						
						If blnChangeFlag = True Then 
 							Set objUser = GetObject(objRecordset.Fields("ADsPath"))
 								objUser.Put "homeDirectory", strHomeDrive
 								objUser.SetInfo
 						Else
 							WScript.Echo "Change not made - change the flag to True if you want changes to take effect"
 						End If 
					End If 
				
				End If 'IsNull
 
				objRecordset.MoveNext
			Loop
		End if
 
End Sub

Open in new window

Avatar of Mike Kline
to find them using adfind use
adfind -b DC=yourdomain,dc=com -f "(&(objectcategory=person)(objectclass=user)(homedirectory=\\server*))"  samaccountname homedirectory
I'll have to play with admod to see how to make the changes.
Script above looks good too.
 
ASKER CERTIFIED SOLUTION
Avatar of LauraEHunterMVP
LauraEHunterMVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of esbfern
esbfern

ASKER

Laura you come through yet again...how do you find out about all this stuff?!?