MSFN Forum: How to select id and username from ads - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to select id and username from ads Rate Topic: -----

#1 User is offline   MAC-DUFF 

  • Junior
  • Pip
  • Group: Members
  • Posts: 54
  • Joined: 05-April 05

Posted 21 May 2006 - 05:22 AM

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


#2 User is offline   Zartach 

  • Junior
  • Pip
  • Group: Members
  • Posts: 91
  • Joined: 24-January 06

Posted 22 May 2006 - 12:51 PM

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


#3 User is offline   MAC-DUFF 

  • Junior
  • Pip
  • Group: Members
  • Posts: 54
  • Joined: 05-April 05

Posted 23 May 2006 - 03:53 AM

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 :)

#4 User is offline   Zartach 

  • Junior
  • Pip
  • Group: Members
  • Posts: 91
  • Joined: 24-January 06

Posted 23 May 2006 - 12:37 PM

View PostMAC-DUFF, on May 23 2006, 03:53 AM, said:

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


#5 User is offline   MAC-DUFF 

  • Junior
  • Pip
  • Group: Members
  • Posts: 54
  • Joined: 05-April 05

Posted 24 May 2006 - 07:02 AM

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.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy