script to modify all users Homedirectory based on input excel spreadsheet with SAMaccountName

Hi
I have been given this script to exract all users with a specific homedirectory attribute (below)

I now need a script that will update this with \\newserver\users\%username% using the excel file created by below script.

csvde -d "DC=Domain,DC=local" -m -f c:\outputtest.csv -l name,sAMAccountName,homeDirectory -r "(&(objectCategory=user)(objectClass=user)(homeDirectory=\5c\5cServer\5cusers*)(cn=*)(displayName=*)(userPrincipalName=*))"


I have also been given a VB script that does the same thing so if either way can be edited to allow me to modify then that would be great

Thanks

Nick



Dim ObjWb
Dim ObjExcel
Dim x, zz

strHomeDirectoryStart = "\\server1\users$"
Set objDomain = GetObject("LDAP://dc=northeast,dc=mydomain,dc=local")
Call ExcelSetup("sheet1") 
x = 1
Call enummembers(objDomain)
Sub enumMembers(objDomain)
	On Error Resume Next
	For Each objMember In objDomain 
		If ObjMember.Class = "user" Then 
			If Left(LCase(ObjMember.HomeDirectory), Len(strHomeDirectoryStart)) = LCase(strHomeDirectoryStart) Then
				x = x +1
				SamAccountName = ObjMember.samAccountName
				Cn = ObjMember.CN
				FirstName = objMember.GivenName
				LastName = objMember.sn
				initials = objMember.initials
				HomeDirectory = ObjMember.HomeDirectory
				HomeDrive = ObjMember.homeDrive
				
				objwb.Cells(x, 1).Value = objMember.Class
				objwb.Cells(x, 2).Value = SamAccountName
				objwb.Cells(x, 3).Value = CN
				objwb.Cells(x, 4).Value = FirstName
				objwb.Cells(x, 5).Value = LastName
				objwb.Cells(x, 6).Value = Initials
				objwb.Cells(x, 7).Value = HomeDirectory
				objwb.Cells(x, 8).Value = HomeDrive
				
				SamAccountName = "-"
				Cn = "-"
				FirstName = "-"
				LastName = "-"
				initials = "-"
				HomeDirectory = "-"
				HomeDrive = "-"
			End If
		End If

		If objMember.Class = "organizationalUnit" or objMember.Class = "container" Then
			enumMembers (objMember)
		End If
	Next
End Sub
Sub ExcelSetup(shtName)
Set objExcel = CreateObject("Excel.Application")
Set objwb = objExcel.Workbooks.Add
Set objwb = objExcel.ActiveWorkbook.Worksheets(shtName)
Objwb.Name = "Active Directory Users" 
objwb.Activate
objExcel.Visible = True
objwb.Cells(1, 2).Value = "SamAccountName"
objwb.Cells(1, 3).Value = "CN"
objwb.Cells(1, 4).Value = "FirstName"
objwb.Cells(1, 5).Value = "LastName"
objwb.Cells(1, 6).Value = "Initials"
ObjWb.Cells(1, 22).Value = "HomeDirectory"
objwb.Cells(1, 23).Value = "HomeDrive"
End Sub
MsgBox "Active Directory Users Done !!!!" 

Toggle HighlightingOpen in New WindowSelect All

Open in new window

LVL 5
ncomperAsked:
Who is Participating?
 
yo_beeDirector of Information TechnologyCommented:
Here is the LDIFDE:
ldifde  -d "DC=Domain,DC=local" -m -f c:\outputtest.ldf -l name,sAMAccountName,homeDirectory -r "(&(objectCategory=user)(objectClass=user)(homeDirectory=\5c\5cserver\5cfolder\*)(cn=*)(displayName=*)(userPrincipalName=*))"

Once exported locate the recently outputed file with Notepad.
You will need to do a Find & Replace for the Add value to Modityand Find & Replace for the home directory with the new one.

Before:
dn: CN=512425,OU=Misc Users,OU=All Users,DC=flhlaw,DC=local
changetype: add
homeDirectory: \\Server1\usersfolders\Users\512425
name: 512425
sAMAccountName: 512425

After:
dn: CN=512425,OU=Misc Users,OU=All Users,DC=flhlaw,DC=local
changetype: Modify
homeDirectory: \\Server2\share1\Users\512425
name: 512425
sAMAccountName: 512425

Once done your will run

LDIFDE -i -f c:\outputtest.ldf -s <Domain Controller Name>  
 
0
 
Krzysztof PytkoSenior Active Directory EngineerCommented:
I don't know how to use VBScript for that but I could help you, using Quest PowerShell module for AD (if you're interested). Let me know if you want to do that using PS or wait for VBScript experts.

Quest PS is completely free and can be downloaded from
http://www.quest.com/powershell/activeroles-server.aspx

Regards,
Krzysztof
0
 
yo_beeDirector of Information TechnologyCommented:
You can also try LDIFDE export similar to csvde with the same command switches.
Once exported you can update the ldf file values from ADD to MODIFY.
Then run the import of the file.

0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
Premkumar YogeswaranAnalyst II - System AdministratorCommented:
Hi,

This the tool i would use for Bulk AD modification, instead of going for script...

http://www.wisesoft.co.uk/software/bulkadusers/default.aspx

Hope it helps..

Regards,
Prem
0
 
ncomperAuthor Commented:
Thanks all, i will post back with the solution that worked
0
 
yo_beeDirector of Information TechnologyCommented:
Just out of curiousity.  Why award points prior to confirming one if not all the solutions?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.