[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-10-13
6
Medium Priority
?
487 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:ncomper
6 Comments
 
LVL 39

Assisted Solution

by:Krzysztof Pytko
Krzysztof Pytko earned 498 total points
ID: 36960947
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
 
LVL 24

Expert Comment

by:yo_bee
ID: 36961423
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
 
LVL 17

Assisted Solution

by:Premkumar Yogeswaran
Premkumar Yogeswaran earned 501 total points
ID: 36961485
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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
LVL 24

Accepted Solution

by:
yo_bee earned 501 total points
ID: 36961695
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
 
LVL 5

Author Closing Comment

by:ncomper
ID: 37043301
Thanks all, i will post back with the solution that worked
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 37044736
Just out of curiousity.  Why award points prior to confirming one if not all the solutions?
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

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

A hard and fast method for reducing Active Directory Administrators members.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
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 …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses
Course of the Month18 days, 11 hours left to enroll

834 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