Page 1 of 1 1
Topic Options
#92566 - 2003-07-28 09:30 PM AD Operational Attributes
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I was running a report on our AD database and wanted to pull out certain information, namely the createTimeStamp property for all user accounts. I found that certain properties are Operational Attributes (aka Constructed Attributes). These are values that are not stored in Active Directory, and are therefore only calculated upon request. Additionally, you cannot get these values by performing a Get or GetEx method on them.

I was able to Google a method for retrieving these values and have converted it to a KiX function. Comments, observations, and improvements are welcome...



Break On CLS

$nul=SetOption("WrapAtEOL","On")
$nul=SetOption("Explicit","On")

Dim $

fnGetOperationalAttribute("@USERID","createTimeStamp") ?
@ERROR " | " @SERROR ?
fnGetOperationalAttribute("@USERID","modifyTimeStamp") ?
@ERROR " | " @SERROR ?
fnGetOperationalAttribute("@USERID","whenCreated") ?
@ERROR " | " @SERROR ?

Get $

Function fnGetOperationalAttribute($sNTName,$sProperty)
    Dim $strDNSDomain,$objCommand,$objConnection,$objRecordSet
   
    $strDNSDomain = "<LDAP://" + GetObject("LDAP://rootDSE").Get("defaultNamingContext")
    If @ERROR<0 Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf

    $objCommand = CreateObject("ADODB.Command")
    $objConnection = CreateObject("ADODB.Connection")
    $objConnection.Provider = "ADsDSOObject"
    $objConnection.Open("Active Directory Provider")
    $objCommand.ActiveConnection = $objConnection
    $objCommand.CommandText = $strDNSDomain + ">;(sAMAccountName=" + $sNTName + ");" +
        $sProperty + ";subtree"
    $objCommand.Properties("Page Size").value = 100
    $objCommand.Properties("Timeout").value = 30
    $objCommand.Properties("Searchscope").value = 2
    $objCommand.Properties("Cache Results").value = False
    $objRecordSet = $objCommand.Execute
    If @ERROR<0 Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf
    $fnGetOperationalAttribute = "" + $objRecordSet.Fields($sProperty)
EndFunction



[ 28. July 2003, 21:31: Message edited by: Chris S. ]

Top
#92567 - 2003-07-28 09:39 PM Re: AD Operational Attributes
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
look'n pretty good...

Suggestion: Pass in an array of fields or string to return. This will save the overhead of creating the ADO object and querying the AD over and over.

Return array or string depending on input.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92568 - 2003-07-28 09:41 PM Re: AD Operational Attributes
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Ja, thought of that. I need help on formulating the .CommandText. [Frown]
Top
#92569 - 2003-07-28 09:43 PM Re: AD Operational Attributes
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
You have a generic query there that brings back all kinds of stuff I believe. Put the code (the while loop for outputing data) from my other post in there and see how many fields you have.

[ 28. July 2003, 21:44: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92570 - 2003-07-28 09:47 PM Re: AD Operational Attributes
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
You will need to alter the query for more than one user though.

Maybe the ADO object should be outside this udf? This would require helper UDFs though.

[ 28. July 2003, 22:00: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92571 - 2003-07-28 09:57 PM Re: AD Operational Attributes
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The whole things looks like a database and you might be able to utilize some of the database UDFs like DBCommand().
_________________________
There are two types of vessels, submarines and targets.

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
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.055 seconds in which 0.024 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