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?
Active Directory

Avatar of undefined
Last Comment
esbfern

8/22/2022 - Mon
Krys_K

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

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
LauraEHunterMVP

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
esbfern

Laura you come through yet again...how do you find out about all this stuff?!?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck