Page 1 of 1 1
Topic Options
#152934 - 2005-12-06 12:19 PM Extracting Info From Active Directory
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
By experimentation I have determined the macro @FullName takes the Active Directory General Tab 'Display Name' and the @Comment the 'Description'.
There currently does not appear to be any other macros to obtain the Telephone number or e-mail address so I presume there is a LDAP COM method to get this info.
Does anyone know of a matrix showing what these objects are called relative to the displayed AD dialogue to enable me to try and extract the basic info I need? Mainly interested in the Geneal Tab.
HAS ANYONE DONE THIS BEFORE ~ WORKING EXAMPLES ?

Top
#152935 - 2005-12-06 12:49 PM Re: Extracting Info From Active Directory
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
I don't have a working example but the UDF below could help you.

http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=141262&an=0&page=1&vc=1

List of all AD attributes.
The following attributes are defined by Active Directory.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#152936 - 2005-12-06 01:21 PM Re: Extracting Info From Active Directory
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
Looks promising but very labourious; all to retrieve an email and telephone number...

Thanks

Top
#152937 - 2005-12-06 01:41 PM Re: Extracting Info From Active Directory
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
PFFT!
Most of the work (coding the UDF) has already been done for you. All you need to do is feed in the parms to the query.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#152938 - 2005-12-09 11:29 AM Re: Extracting Info From Active Directory
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
I am REALLY finding it dificult identifing the AD objects containing the relevant info. Even before I can search for anything ? This is where I am at and need help both filling in the gaps and formulating a search qery.

GENERAL TAB:
First Name = #4 ?
Initials =
Last Name = #7 ?
Display Name = @FullName or #10
Description = @Comment or #11
Office = #1 or #5 ?
Telephone Number = #8 ?
E-Mail = #3 ? Primary
Web Page =

ADDRESS TAB:
Street = #6 ?
P.O.Box =
City = #9 ??
State/province =
Zip/Postal code =

http://msdn.microsoft.com/library/defaul...ributes_all.asp
#1
buildingName
The buildingName attribute type specifies the name of the building where an organization or organizational unit is based.
CN buildingName
Ldap-Display-Name buildingName
#2
Address
The user's address.
CN Address
Ldap-Display-Name streetAddress
#3
E-mail-Addresses
The list of email addresses for a contact.
CN E-mail-Addresses
Ldap-Display-Name mail
#4
Given-Name
Contains the given name (first name) of the user.
CN Given-Name
Ldap-Display-Name givenName
#5
Location
The user's location such as office number.
CN Location
Ldap-Display-Name location
#6
Street-Address
The street address.
CN Street-Address
Ldap-Display-Name street
#7
Surname
This attribute contains the family or last name for a user.
CN Surname
Ldap-Display-Name sn
#8
Telephone-Number
The primary telephone number.
CN Telephone-Number
Ldap-Display-Name telephoneNumber
#9
Locality-Name
Represents the name of a locality, such as a town or city.
CN Locality-Name
Ldap-Display-Name l
#10
Display-Name
The display name for an object. This is usually the combination of the users first name, middle initial, and last name.
CN Display-Name
Ldap-Display-Name displayName
#11
Description
Contains the description to display for an object. This value is treated as single-valued by the system.
CN Description
Ldap-Display-Name description

Top
#152939 - 2005-12-09 01:04 PM Re: Extracting Info From Active Directory
GSUK Offline
Starting to like KiXtart

Registered: 2004-03-10
Posts: 125
The easiest way I found the object names was:

Run the CSVDE.exe program (part of the server resource kit) on a DC and export the contents of an OU to a .CSV file. The file will header each column with the object name. Use these names to reference the objects in AD.

Hope this helps.

Top
#152940 - 2005-12-13 02:34 PM Re: Extracting Info From Active Directory
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
Generally things work however I cannot get 'description' to work. Looks like the array is out of bounds for the type of data returned. Can anyone help ?
Code:
  
break on
setoption("NoVarInString","Off")
include ".\fnLDAPQuery.kix"
Global $FullName
GLobal $Suffix
Global $Title
Global $Mobile
Global $email
Global $Comment
$USERNAME="%username%"

$sADsPath = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")
$strFilter = "(&(objectClass=User)(sAMAccountName="+$USERNAME+"))"

$aAttributes = "sAMAccountName", "displayName"
$aResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"sAMAccountName")
$FullName= $aResults[Ubound($aResults),UBound($aResults,2)]
$aAttributes = "sAMAccountName", "physicalDeliveryOfficeName"
$aResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"sAMAccountName")
$SUFFIX= $aResults[Ubound($aResults),UBound($aResults,2)]
; $aAttributes = "sAMAccountName", "description"
; $aResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"sAMAccountName")
;$Title= $aResults[Ubound($aResults),UBound($aResults,2)]
$Title=@comment
$aAttributes = "sAMAccountName", "telephoneNumber"
$aResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"sAMAccountName")
$Mobile= $aResults[Ubound($aResults),UBound($aResults,2)]
$aAttributes = "sAMAccountName", "mail"
$aResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"sAMAccountName")
$email= $aResults[Ubound($aResults),UBound($aResults,2)]
$aAttributes = "sAMAccountName", "wWWHomePage"
$aResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"sAMAccountName")
$Comment= $aResults[Ubound($aResults),UBound($aResults,2)]

? $FullName+" "+$Suffix
? $Title
? $Mobile
? $email
? $Comment

sleep 10


Top
#152941 - 2005-12-13 04:41 PM Re: Extracting Info From Active Directory
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
The description property is an array. You will have to handle the array of values appropriately (join the data, For...Each it, etc.).
Top
#152942 - 2005-12-13 05:02 PM Re: Extracting Info From Active Directory
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
$ldap = TranslateName(1, @domain, 3, @ldomain+'\'+@userid, 1)
$OU = LDAPArray($ldap[0],'OU')[1]
$UserProperties = GetObject("LDAP://"+$LDAP[0])
$FirstName = $userProperties.FirstName
$LastName = $userProperties.LastName
$Description = $userProperties.Description
$UserProperties = 0
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#152943 - 2005-12-13 11:19 PM Re: Extracting Info From Active Directory
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Rad has a point here, implicit though it is....

What are you gathering this information for? Is it for an admin script (where you might be running this against many accounts) or a logon script (where you might be running this against one user)?

Top
#152944 - 2005-12-20 01:32 PM Re: Extracting Info From Active Directory
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
For consistency we have a central standard for such as email footers. I have written a script to generate email footers on login in HTML + RTF + TXT with logos etc using the core information stored in AD. Used to have to Word Process every type for every user. The key value is the logon name = %username%
on which all other factors are retrieved. The UDF is good but slow when I know what it is I want to retrieve. However I do not know the HOW other than shown above using the UDF. I want to be able to retrieve the description associated with a user name. For the likes of Personal Assistants, their group membership will require that they not only have their own email footers but that of their bosses and hence the need for LDAP rather than just @description which limits it to only the 'present' username.
If anyone can help me speed up and narrow down the extracted info this will allow me to loose the @description currently in place and get over the PA issue.

Top
#152945 - 2005-12-20 11:39 PM Re: Extracting Info From Active Directory
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Does this get you closer to your goal?

Code:
Break on
SetOption("NoVarInString","Off")
include "K:\Functions\fnLDAPQuery.kix"
Global $FullName
Global $Suffix
Global $Title
Global $Mobile
Global $email
Global $Comment
$USERNAME="%username%"

$sADsPath = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")
$strFilter = "(&(objectClass=User)(sAMAccountName="+$USERNAME+"))"

$aAttributes = "displayName", "physicalDeliveryOfficeName", "description", "telephoneNumber", "mail", "wWWHomePage"
$aResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter)

? "Fullname: " + $aResults[0,0]
? "Suffix: " + $aResults[0,1]
? "Title: " + IIf(VarType($aResults[0,2]) & 8192,Join($aResults[0,2]),$aResults[0,2])
? "Mobile: " + $aResults[0,3]
? "Email: " + $aResults[0,4]
? "HomePage: " + $aResults[0,5]

?? "Done." Get $


Top
#152946 - 2005-12-21 04:35 PM Re: Extracting Info From Active Directory
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
You are a star, looks to do the job in double time.

DOES ANYONE KNOW WHETHER KIX2010 WILL FUNCTION ON AN XP x64 BOX ~ Building one in new year ?

Top
#152947 - 2005-12-21 06:33 PM Re: Extracting Info From Active Directory
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Yes KiX runs on XP64
Top
#152948 - 2005-12-31 03:53 PM Re: Extracting Info From Active Directory
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
And please don't shout.
_________________________
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
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.072 seconds in which 0.028 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