Hi, we've migrated hundreds of users from an NT domain into 2003 AD. I have a spreadsheet ( .csv file, as opposed to .xls ) with five columns in it. The first column has a title of ""givenName" (in Column A, Row 1) and includes the first name of all of our users underneath it. The second column is titled "telephoneNumber" with the telephone extensions of all our users underneath it, the third column is titled "description", the fourth is titled "sn" for surname, and the fifth is the "DN" for each user. DN as in, CN=username,OU=Users,DC=domain,DC=com
I've extracted all of this information using the Microsoft CSVDE utility.
What we're trying to do is populate the AD User Account properties in a specific OU for the following....
"First name:"
"Last name:"
"Description"
"Telephone number:"
"E-Mail"
The "Display Name" for all of the users is already filled in. I've attempted to do this by borrowing a script that I've copied and pasted from this post...
thread329-1087357
I can get the following populated...
"First name:"
"Last name:"
"E-Mail"
but cannot populate the Telephone Number or Description fields. Here is the version of the script that I have edited.
Option Explicit
Dim oContainer, InfoFile, FileSystem, SourceFile, sLine(), aLine,DN
Dim DC, DC1, DC2, OU, i, oUser2, oCont2, aLine1
'Prompt to get AD domain name to make an LDAP connection to
DN = InputBox ("Please enter AD Domain name")
'split the domain name at the period, so I can feed the LDAP query correctly
DC = Split(DN, ".",-1,1)
DC1 = DC(0)
DC2 = DC(1)
'verify the user typed in the correct domain name, going to add some more prompts to this later
MsgBox ("The domain name you entered is " & DC1 & "." & DC2)
'Get the name of the OU the user wants to modify users objects for. all user objects in the OU
'will be modified
OU = InputBox ("Please enter the User container OU that you wish to modify")
'line 20 Let user verify the entered the correct OU
MsgBox ("All user objects in the " & OU & " OU will be modified")
'Make LDAP connection to the domain and OU specified above
Set oContainer=GetObject("LDAP://OU=" & OU &",DC=" & DC1 & ",DC=" & DC2)
EnumerateUsers oContainer 'This sub works fine, it puts the correct data where I want it
AddInfo oContainer 'This is the sub I am having problems With
Sub EnumerateUsers(oCont)
'This sub gets the UserDisplay attribute in AD, splits it and populates the First Name
'Last Name, e-mail address attrib for the user object. Also does the AD logon name and domain
'name
Dim oUser, UserCN, UserDisplay, givenName, sn, telephoneNumber, description, aLine, fInit, GoNext
For Each oUser In oCont
Select Case LCase(oUser.Class)
Case "user"
If Not IsEmpty(oUser.cn) Then
UserCN = oUser.cn
End If
If Not IsEmpty(oUser.DisplayName) Then
UserDisplay = oUser.DisplayName
aLine = split(UserDisplay, " ",-1,1)
givenName = aLine(0)
sn = aLine(1)
End If
fInit = Mid(givenName,1,1)
If IsEmpty (oUser.Mail) Then
oUser.Put "mail", LCase(givenName) & "." & LCase(sn) & "@mydomain.com"
End If
If IsEmpty (oUser.GivenName) Then
oUser.Put "GivenName", givenName
End If
If IsEmpty (oUser.sn) Then
oUser.Put "sn", sn
End If
If IsEmpty (oUser.UserPrincipalName) Then
oUser.Put "UserPrincipalName", UserCN & "@domain.com"
End If
oUser.SetInfo
EnumerateUsers oUser
'This sub should read a .csv file, put the attributes in an array, then go through the users in the
'OU and add the values from the array
End Select
Next
End Sub
Sub AddInfo(oCont)
Dim FileSystem,SourceFile,sLine,aLine1,givenName,telephoneNumber,description,sn,i,oUser
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set SourceFile = FileSystem.OpenTextFile("C:\csvdeexport.csv",1)
i=1
For Each oUser In oCont
Select Case LCase(oUser.Class)
Case "user"
if SourceFile.atEndOfStream then
wscript.echo "Line: " & i & vbcrlf & "Prematured end, not enough data to process."
else
sLine=SourceFile.ReadLine
aLine1 = Split(sLine, ",",-1,1)
if ubound(aLine1)<>6 then
givenName = aLine1(0)
telephoneNumber = aLine1(1)
description = aLine1(2)
If IsEmpty (oUser.telephoneNumber) Then
oUser.Put "telephoneNumber", telephoneNumber
End If
If IsEmpty (oUser.description) Then
oUser.Put "description", description
End If
oUser.SetInfo
end if
i=i+1
end if
case else
'do nothing
End Select
Next
SourceFile.close
set SourceFile=nothing
set FileSystem=nothing
End Sub
Rather than filling in the Telephone Number and Description for the individual users, the script enters the titles of both of these columns for the users. In other words in the User Account properties under telephone, I don't have their 4 digit extension, I have the column title "telephone". The same applies for description. How do I tell the script to say, here's the user's name, now populate the user's telephone number with the corresponding number in the "telephone" column in the csvdeexport.csv file?
any takers on this one?
I've extracted all of this information using the Microsoft CSVDE utility.
What we're trying to do is populate the AD User Account properties in a specific OU for the following....
"First name:"
"Last name:"
"Description"
"Telephone number:"
"E-Mail"
The "Display Name" for all of the users is already filled in. I've attempted to do this by borrowing a script that I've copied and pasted from this post...
thread329-1087357
I can get the following populated...
"First name:"
"Last name:"
"E-Mail"
but cannot populate the Telephone Number or Description fields. Here is the version of the script that I have edited.
Option Explicit
Dim oContainer, InfoFile, FileSystem, SourceFile, sLine(), aLine,DN
Dim DC, DC1, DC2, OU, i, oUser2, oCont2, aLine1
'Prompt to get AD domain name to make an LDAP connection to
DN = InputBox ("Please enter AD Domain name")
'split the domain name at the period, so I can feed the LDAP query correctly
DC = Split(DN, ".",-1,1)
DC1 = DC(0)
DC2 = DC(1)
'verify the user typed in the correct domain name, going to add some more prompts to this later
MsgBox ("The domain name you entered is " & DC1 & "." & DC2)
'Get the name of the OU the user wants to modify users objects for. all user objects in the OU
'will be modified
OU = InputBox ("Please enter the User container OU that you wish to modify")
'line 20 Let user verify the entered the correct OU
MsgBox ("All user objects in the " & OU & " OU will be modified")
'Make LDAP connection to the domain and OU specified above
Set oContainer=GetObject("LDAP://OU=" & OU &",DC=" & DC1 & ",DC=" & DC2)
EnumerateUsers oContainer 'This sub works fine, it puts the correct data where I want it
AddInfo oContainer 'This is the sub I am having problems With
Sub EnumerateUsers(oCont)
'This sub gets the UserDisplay attribute in AD, splits it and populates the First Name
'Last Name, e-mail address attrib for the user object. Also does the AD logon name and domain
'name
Dim oUser, UserCN, UserDisplay, givenName, sn, telephoneNumber, description, aLine, fInit, GoNext
For Each oUser In oCont
Select Case LCase(oUser.Class)
Case "user"
If Not IsEmpty(oUser.cn) Then
UserCN = oUser.cn
End If
If Not IsEmpty(oUser.DisplayName) Then
UserDisplay = oUser.DisplayName
aLine = split(UserDisplay, " ",-1,1)
givenName = aLine(0)
sn = aLine(1)
End If
fInit = Mid(givenName,1,1)
If IsEmpty (oUser.Mail) Then
oUser.Put "mail", LCase(givenName) & "." & LCase(sn) & "@mydomain.com"
End If
If IsEmpty (oUser.GivenName) Then
oUser.Put "GivenName", givenName
End If
If IsEmpty (oUser.sn) Then
oUser.Put "sn", sn
End If
If IsEmpty (oUser.UserPrincipalName) Then
oUser.Put "UserPrincipalName", UserCN & "@domain.com"
End If
oUser.SetInfo
EnumerateUsers oUser
'This sub should read a .csv file, put the attributes in an array, then go through the users in the
'OU and add the values from the array
End Select
Next
End Sub
Sub AddInfo(oCont)
Dim FileSystem,SourceFile,sLine,aLine1,givenName,telephoneNumber,description,sn,i,oUser
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set SourceFile = FileSystem.OpenTextFile("C:\csvdeexport.csv",1)
i=1
For Each oUser In oCont
Select Case LCase(oUser.Class)
Case "user"
if SourceFile.atEndOfStream then
wscript.echo "Line: " & i & vbcrlf & "Prematured end, not enough data to process."
else
sLine=SourceFile.ReadLine
aLine1 = Split(sLine, ",",-1,1)
if ubound(aLine1)<>6 then
givenName = aLine1(0)
telephoneNumber = aLine1(1)
description = aLine1(2)
If IsEmpty (oUser.telephoneNumber) Then
oUser.Put "telephoneNumber", telephoneNumber
End If
If IsEmpty (oUser.description) Then
oUser.Put "description", description
End If
oUser.SetInfo
end if
i=i+1
end if
case else
'do nothing
End Select
Next
SourceFile.close
set SourceFile=nothing
set FileSystem=nothing
End Sub
Rather than filling in the Telephone Number and Description for the individual users, the script enters the titles of both of these columns for the users. In other words in the User Account properties under telephone, I don't have their 4 digit extension, I have the column title "telephone". The same applies for description. How do I tell the script to say, here's the user's name, now populate the user's telephone number with the corresponding number in the "telephone" column in the csvdeexport.csv file?
any takers on this one?