Page 1 of 1 1
Topic Options
#128249 - 2004-10-21 02:48 PM search for a user in AD
jan Offline
Getting the hang of it

Registered: 2004-07-07
Posts: 66
Hi,

How do I search for a user in AD. I need to search from e.g ou=kpdk,dc=q8int,dc=com and all sub containers. I've tried to look at ADsearch but I'm not sure how to make it work.

Hope someone can help me

Jan

Top
#128250 - 2004-10-21 03:05 PM Re: search for a user in AD
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Why do you have to search?
What key attribute are you searching on?
What do you expect to get back?

If you have the SAMAccountName, you can simply translate it with the TranslateName() UDF.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128251 - 2004-10-21 03:24 PM Re: search for a user in AD
jan Offline
Getting the hang of it

Registered: 2004-07-07
Posts: 66
I have users in different containsers and I don't know in which container they exists. I need to find the full DN of the user in order to get order informations
Top
#128252 - 2004-10-21 03:46 PM Re: search for a user in AD
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
How do you expect to get good support if you don't give good info and don't answer my questions?

Did you even look at the UDF I suggested?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128253 - 2004-10-21 03:51 PM Re: search for a user in AD
Anonymous
Unregistered


Yes I looked at TranslateName and that doesn't seems to solve my problem. Is there a easy way to get DN?
Top
#128254 - 2004-10-21 04:25 PM Re: search for a user in AD
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Give this script a shot and let me know if works.

Code:

break on
? "Enter username: "
gets $user
$OU = getOU($user)
? $OU

function getOU($userName)
dim $dn,$objRootDSE,$strDomain
dim $objConnection,$objCommand
dim $objRecordSet
$getOU = "Not Found"
$objRootDSE = GetObject("LDAP://RootDSE")
$strDomain = $objRootDSE.Get("DefaultNamingContext")

$objConnection = CreateObject("ADODB.Connection")
$objConnection.Open ("Provider=ADsDSOObject;")
$objCommand = CreateObject("ADODB.Command")
$objCommand.ActiveConnection = $objConnection
$objCommand.CommandText =
"<LDAP://" + $strDomain + ">;((saMAccountName=" + $userName + "))" +
";distinguishedName,name;subtree"

$objRecordSet = $objCommand.Execute

While Not $objRecordSet.EOF
$dn = $objRecordSet.Fields("distinguishedName").Value
$getOU = $dn
$objRecordSet.MoveNext
loop
endfunction

_________________________
Eric

Top
#128255 - 2004-10-21 04:32 PM Re: search for a user in AD
Anonymous
Unregistered


I tried your script and it didn't worked. Isn't it because I need to type in the LDAP parameters? E.g.
(LDAP://ou=kpdk,dc=q8int,dc=com)?

Jan

Top
#128256 - 2004-10-21 04:49 PM Re: search for a user in AD
jan Offline
Getting the hang of it

Registered: 2004-07-07
Posts: 66
My mistake, it works now. Many thanks for your help :-)
Top
#128257 - 2004-10-22 04:16 PM Re: search for a user in AD
jan Offline
Getting the hang of it

Registered: 2004-07-07
Posts: 66
Hi,

Now I want to use the var it returns, but when I use it I get an errormsg: IDispatch pointers not allowed in expressions!

Here is the code:

FUNCTION mailbox($getou)
$mailbox=GETOBJECT("LDAP://$getou")
? "getobj @serror"
;? "Mailbox Information for $username:"
;? "User Information:"
;? "Display Name: " $mailbox.get("cn")
;? "Given Name: " $mailbox.get("givenname")
;? "Last Name: " $mailbox.get("sn")
;? "Alias: " $mailbox.get("uid")
;? "Mailbox Information:"
;? "Primary SMTP: " $mailbox.get("mail")
;? "X.400 Address: " $mailbox.get("textencodedoraddress")
;? "Home MTA: " $mailbox.get("home-mta")
;? "Home MDA: " $mailbox.get("home-mda")

ENDFUNCTION


function getOU($userName)
DIM $dn,$objRootDSE,$strDomain
DIM $objConnection,$objCommand
DIM $objRecordSet
$getOU = "Not Found"
$objRootDSE = GETOBJECT("LDAP://RootDSE")
$strDomain = $objRootDSE.Get("DefaultNamingContext")

$objConnection = CREATEOBJECT("ADODB.Connection")
$objConnection.Open ("Provider=ADsDSOObject;")
$objCommand = CREATEOBJECT("ADODB.Command")
$objCommand.ActiveConnection = $objConnection
$objCommand.CommandText =
"<LDAP://" + $strDomain + ">;((saMAccountName=" + $userName + "))" +
";distinguishedName,name;subtree"

$objRecordSet = $objCommand.Execute

WHILE Not $objRecordSet.EOF
$dn = $objRecordSet.Fields("distinguishedName").Value
$getOU = $dn
$objRecordSet.MoveNext
LOOP

mailbox($getou)

ENDFUNCTION


BREAK on

? "Enter username: " GETS $username

getOU($username)

Hope you can help me

Top
#128258 - 2004-10-22 05:12 PM Re: search for a user in AD
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Your Get's are objects. Objects cannot be outputed to a console.

$mailbox.get("cn")

Top
#128259 - 2004-10-22 05:18 PM Re: search for a user in AD
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
... is commented out.

However there is some confusion I think between variable names and function return variable names that will definitely bite.

Also the return from the function is itself an object which is being mishandled.

Top
#128260 - 2004-10-25 11:10 AM Re: search for a user in AD
jan Offline
Getting the hang of it

Registered: 2004-07-07
Posts: 66
Hi,

Well I also get the error for these lines:
$mailbox=GETOBJECT("LDAP://$getou")

and that's not to output to the console

Top
#128261 - 2004-10-26 03:10 AM Re: search for a user in AD
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
So, where do you set the $GetOU variable? Please show complete code when asking for help.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1471 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.068 seconds in which 0.03 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org