Page 1 of 1 1
Topic Options
#187404 - 2008-04-30 09:05 PM Searching for a specific user in AD via the SAM account name
Thallium Offline
Just in Town

Registered: 2002-02-26
Posts: 4
I need to search for a user based on their SAM account name; I've tried different variations on GetObject("LDAP://etc") and while I can connect to Active Directory, query the OU I want and list everything in it as an array, I need to be more specific and only search for the exact object I need. How can I do this?
Top
#187419 - 2008-05-01 08:05 AM Re: Searching for a specific user in AD via the SAM account name [Re: Thallium]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Are you just asking for the attibute name (SAMAccountName), or the code to search the entire directory to find a specified account name.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#187427 - 2008-05-01 03:45 PM Re: Searching for a specific user in AD via the SAM account name [Re: Thallium]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
Thallium,
Is this what you are looking for:
 Code:
CheckForUser("tuser") ;samAccountName

Function CheckForUser($samAccountName)
	
  $objRootDSE = GetObject("LDAP://rootDSE")
  $defaultNamingContext = $objRootDSE.Get("defaultNamingContext")
  
	$strUserName = $samAccountName
	$objConnection = CreateObject("ADODB.Connection")
	$objConnection.Open ("Provider=ADsDSOObject;")

	$objCommand = CreateObject("ADODB.Command")
	$objCommand.ActiveConnection = $objConnection

	$objCommand.CommandText = "<LDAP://" + $defaultNamingContext + ">;(&(objectCategory=User)(samAccountName=" + $strUserName + "));samAccountName;subtree"
   
	$objRecordSet = $objCommand.Execute

	If $objRecordset.RecordCount = 0
		? "sAMAccountName: " + $strUserName + " does not exist."
	Else
		? $strUserName + " exists."
	EndIf

	$objConnection.Close

EndFunction
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#187431 - 2008-05-02 12:42 AM Re: Searching for a specific user in AD via the SAM account name [Re: Benny69]
Thallium Offline
Just in Town

Registered: 2002-02-26
Posts: 4
Benny69 - that works great, thanks!
Top
#187806 - 2008-05-21 08:42 PM Re: Searching for a specific user in AD via the SAM account name [Re: Thallium]
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
Here an example we use to search for users, email-addresses or phone numbers. The .mui contains the dutch language. If you add an extra section in it with the language code you can easy add extra languages.

In the .kix and .mui there can be entries you have to alter to meet your business name. Also in the .mui file there is an entry that defines you're base DN from where the app searches.


Attachments
SearchUser.zip (772 downloads)
Description: Contains three files. Needed KiXtart 4.52+ and KiXforms 2.46.55.0.

128.jpg
Description:


_________________________
Kind regards,

Top
#189272 - 2008-08-26 01:23 AM Re: Searching for a specific user in AD via the SAM account name [Re: Benny69]
Gerald_G Offline
Fresh Scripter

Registered: 2005-04-11
Posts: 34
Loc: Canada
How would you modify this to return the users CN once found ?
Top
#189278 - 2008-08-26 02:10 AM Re: Searching for a specific user in AD via the SAM account name [Re: Gerald_G]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
See the UDF TRANSLATENAME() http://www.kixtart.org/UDF/UDF_lister.php?what=post&code=83002
_________________________
Today is the tomorrow you worried about yesterday.

Top
#189286 - 2008-08-26 06:52 PM Re: Searching for a specific user in AD via the SAM account name [Re: Gargoyle]
Gerald_G Offline
Fresh Scripter

Registered: 2005-04-11
Posts: 34
Loc: Canada
I can't get translatename() to find a user at all.
Not sure where I'm going wrong.

I also notice in the notes, no Integer value for NameType for samAccountNAme. (which is what I need to find the user by).

Top
#189287 - 2008-08-26 07:50 PM Re: Searching for a specific user in AD via the SAM account name [Re: Gerald_G]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
There are many examples here on the board

My string that I use all of the time is like this

If TranslateName (3,"",3,@domain+"\"+@User,1)[1] <> 0
MessageBox("Invalid User","Error",16)
EndIf
_________________________
Today is the tomorrow you worried about yesterday.

Top
#189288 - 2008-08-26 08:09 PM Re: Searching for a specific user in AD via the SAM account name [Re: Gerald_G]
Gerald_G Offline
Fresh Scripter

Registered: 2005-04-11
Posts: 34
Loc: Canada
Edit - I got it thanks.

Figured out how to add fields to the recordset, and then access them using RecordSet.fields().

I now have a function that looks up an ID by samAccountName and returns the CN.

Thanks again folks !!

Top
#189289 - 2008-08-26 09:02 PM Re: Searching for a specific user in AD via the SAM account name [Re: Gerald_G]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
So lets see it. This board works because we share.
Top
Page 1 of 1 1


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

Who's Online
0 registered and 405 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

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

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