Jump to content

How to select id and username from ads


Recommended Posts

hi,

I look for a solution how to select the user out of the ads like this:

s12345(login-name);firstname secondname

s23456(login-name);firstname secondname

second and firstname can be changed

hope u understand me and can help. I am already infomred about the 2k3 software like ldifde or DSQUERY but i dont get it....

cu later

Link to comment
Share on other sites


It is not exactly what you asked for but i was not sure on how to do it like that.

I have made a script with the help of technet :lol:

Save the code in a file called export.vbs or something.

'Global variables
Dim oContainer
Dim OutPutFile
Dim FileSystem
'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("export.txt", True)
Set oContainer=GetObject("LDAP://OU=flappie,DC=contoso,DC=com")
'Enumerate Container
EnumerateUsers oContainer
'Clean up
OutPutFile.Close
Set FileSystem = Nothing
Set oContainer = Nothing
WScript.Echo "Finished"
WScript.Quit(0)
Sub EnumerateUsers(oCont)
Dim oUser
For Each oUser In oCont
Select Case LCase(oUser.Class)
Case "user"
If Not IsEmpty(oUser.distinguishedName) Then
OutPutFile.WriteLine "dn: " & oUser.distinguishedName
End If
If Not IsEmpty(oUser.userPrincipalName) Then
OutPutFile.WriteLine "UserPrincipalName: " & oUser.userPrincipalName
End If
If Not IsEmpty(oUser.sAMAccountName) Then
OutPutFile.WriteLine "Username: " & oUser.sAMAccountName
End If
If Not IsEmpty(oUser.name) Then
OutPutFile.WriteLine "name: " & oUser.Get ("name")
End If
Case "organizationalunit", "container"
EnumerateUsers oUser
End Select
OutPutFile.WriteLine
Next
End Sub

And it will show the result in the textfile export.txt like this:

dn: CN=John Smith,OU=Flappie,DC=contoso,DC=com
UserPrincipalName: jsmith@contoso.com
Username: jsmith
name: John Smith

Link to comment
Share on other sites

hi, thats nice. but later I want to insert it in a mysql database where I want to part it through a ',' or a ';'. perhaps u know a other solution. that my main target, to get the information about userid and name in a db :)

Link to comment
Share on other sites

hi, thats nice. but later I want to insert it in a mysql database where I want to part it through a ',' or a ';'. perhaps u know a other solution. that my main target, to get the information about userid and name in a db :)

Í'll try :P

Here try this one, the code:

'Global variables
Dim oContainer
Dim OutPutFile
Dim FileSystem
'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("export3.txt", True)
'change the domain and OU to match yours ofcource;-)
Set oContainer=GetObject("LDAP://OU=flappie,DC=contoso,DC=com")
'Enumerate Container
EnumerateUsers oContainer
'Clean up
OutPutFile.Close
Set FileSystem = Nothing
Set oContainer = Nothing
WScript.Echo "Finished"
WScript.Quit(0)
Sub EnumerateUsers(oCont)
Dim oUser
For Each oUser In oCont
Select Case LCase(oUser.Class)
Case "user"
If Not IsEmpty(oUser.sAMAccountName) Then
OutPutFile.Write oUser.sAMAccountName & ";"
End If
If Not IsEmpty(oUser.name) Then
OutPutFile.WriteLine oUser.Get ("name")
End If
Case "organizationalunit", "container"
EnumerateUsers oUser
End Select
OutPutFile.WriteLine
Next
End Sub

The result:

jdoe;Jane Doe

jsmith;John Smith

Link to comment
Share on other sites

I am a little bit fascinated by your skills. thats excatly what I ve been looking for such a long time. thank u.

now I only have to make some small changes but I ll try it at first allone.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...