Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Importing additional attributes after CSVDE

Posted on 2008-10-17
3
Medium Priority
?
890 Views
Last Modified: 2013-12-24
Hi,
Inherited an AD setup where previous admin imported pupil information using CSVDE. The only attributes that where in the csv file where the essential, objectClass, sAMAccountName and DN.
I want to be able to populate the other fields, eg displayName, givenName, sn etc. I can do the Profile path using dsquery/dsmod pipes.
I was thinking I could create a new csv file with the relevant structure and attributes but won't that moan that the account already exists?
What's the best way to achieve this?
0
Comment
Question by:SeventhZen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
exx1976 earned 2000 total points
ID: 22742313
This code should do what you want.

You need to edit line 1 with the netbios name of your domain.

The script expects an xls file in the same directory as the script named "Source.xls".

The spreadsheet should have a header row, as this script will start reading information from the second row, and will stop when it encounters a row that is completely blank.  If any column of a row has data, the entire row should be populated.  Column A should be the users SAMAccountName (to locate the user in AD), column B should be the DisplayName you want, colulmn C the GivenName, column D the sn.

Enjoy!
Domain = "MyDomain"
bEmpty = False
sPath = WScript.ScriptFullName
sPath = Left(sPath,Len(sPath)-Len(WScript.ScriptName))
Set oExcelApp = CreateObject("Excel.Application")
Set oWorkbook = oExcelApp.Workbooks.Open(sPath & "Source.xls")
Set oWorksheet = oWorkbook.Worksheets(1)
oWorksheet.Activate
oExcelApp.Visible = False
Dim ArrVals(3)
iCounter = 2
Do Until bEmpty = True
	EmptyCounter = 0
	For q = 0 To 3
   		ArrVals(q) = ""
   		ArrVals(q) = oWorksheet.Cells(iCounter, q + 1)
   		If ArrVals(q) = "" Then EmptyCounter = EmptyCounter + 1
   	Next
   	If EmptyCounter = 4 Then 
   		bEmpty = True
    End If
    iCounter = iCounter + 1
Loop
bEmpty = False
iCounter = 2
Do Until bEmpty = True
	EmptyCounter = 0
	For q = 0 To 3
		ArrVals(q) = ""
		ArrVals(q) = oWorksheet.Cells(iCounter, q + 1)
		If ArrVals(q) = "" Then EmptyCounter = EmptyCounter + 1
	Next
	If EmptyCounter = 0 Then
    	AddAttributes ArrVals(0), ArrVals(1), ArrVals(2), ArrVals(3)
    	iCounter = iCounter + 1
    End If
    If EmptyCounter = 4 Then bEmpty = True
Loop
If iCounter = 2 Then 
	oWorkbook.Save
	oExcelApp.Quit
	WScript.Quit()
End If
 
 
Sub AddAttributes(byVal samAccountName, byVal DisplayName, byVal GivenName, byVal sn)
	DN = GetObjectDN(samAccountName,Domain)
	Set oUser = GetObject("LDAP://" & DN)
	oUser.DisplayName = Displayname
	oUser.sn = sn
	oUser.GivenName = GivenName
	oUser.SetInfo
End Sub
 
Function GetObjectDN(strObject, strDomain)
      Const ADS_NAME_INITTYPE_GC = 3
      Const ADS_NAME_TYPE_1779 = 1
      Const ADS_NAME_TYPE_NT4 = 3
      Dim objNameTranslate
      Dim strObjectDN
      On Error Resume Next : Err.Clear
      Set objNameTranslate = CreateObject("NameTranslate")
      objNameTranslate.Init ADS_NAME_INITTYPE_GC, ""
      objNameTranslate.Set ADS_NAME_TYPE_NT4, strdomain & "\" & strObject
      strObjectDN = objNameTranslate.Get(ADS_NAME_TYPE_1779)
      If Err.Number <> 0 Then
            strObjectDN = ""
      End If
      Set objNameTranslate = Nothing
      On Error Goto 0
      GetObjectDN = strObjectDN
End Function

Open in new window

0
 
LVL 1

Author Comment

by:SeventhZen
ID: 22784885
Thanks for this, I wouldn't have had a clue.
I'm assuming this needs to be saved as a vbs file and run using cscript before the path to the script.

I'm on site tomorrow so I will let you know.

Cheers
0
 
LVL 1

Author Comment

by:SeventhZen
ID: 22883990
Thanks for this, worked like a charm.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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…

715 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