|
-
Jun 24th, 2006, 12:30 AM
#1
Thread Starter
Registered User
sam account name from AD
I trying to get a listing of sam account names from the active directory, But Im getting a list of everything including computernames, and displayname of default users. Can anyone tell me hopw to just get "sam account names", here is the code ive got now Im connecting to a root domain and putting the data in a access database:
On Error Resume Next
Dim conAD As New ADODB.Connection
Dim rsAD As New ADODB.Recordset
Dim comAD As New ADODB.Command
Dim oRootDSE
Dim oMydomain
'choose provider
conAD.Provider = "ADsDSOObject"
'open the data dase
conAD.Open()
'Assign the command object for this connection
comAD.ActiveConnection = conAD
'Create a search string
oRootDSE = GetObject("LDAP://RootDSE")
oMydomain = GetObject("LDAP://" & oRootDSE.Get("defaultNamingContext"))
comAD.CommandText = "<" & oMydomain.adspath & ">;(objectClass=user);samaccountname"
'MsgBox(comAD.CommandText)
'Execute(query)
rsAD = comAD.Execute
'Navigate()
Do Until rsAD.EOF
rsAC.AddNew()
rsAC.Fields("FirstName").Value = " "
rsAC.Fields("LastName").Value = " "
rsAC.Fields("UserName").Value = rsAD.Fields(0).Value
rsAC.Fields("DomainN").Value = oMydomain.name
rsAC.Fields("StreetAddress").Value = " "
rsAC.Fields("Suburb").Value = " "
rsAC.Fields("PositionN").Value = " "
rsAC.UpdateBatch()
rsAD.MoveNext()
Loop
conAD.Close()
If Err.Number <> 0 Then
MsgBox(Err.Number)
MsgBox(Err.Description)
Else : MsgBox("data entered")
End If
-
Jun 26th, 2006, 07:12 AM
#2
Member
Re: sam account name from AD
Are you trying to display this Sam account value or set it to a variable?
You have the query returing only sam accounts but you don't have anything to display or set that information.
MySamAcc = rsAC.Fields("SamAccountName")
or
Msgbox rsAC.Fields("SamAccountName")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|