Page 3 of 3 <123
Topic Options
#141680 - 2005-06-15 10:15 PM Re: Please help
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
I'm not saying you HAVE to use KiXforms, just saying that if your LDAP path is wrong you will not get the data back.

This browser will automatically allow you to browse to the object and then copy the LDAP path for use in your script.

Can you see this data on the user in question being tested within the Active Directory Users and Computer MMC?
 

Top
#141681 - 2005-06-15 10:24 PM Re: Please help
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Last try. This returns all results for all user accounts in your domain.

Code:

$sWhat = "Name","physicalDeliveryOfficeName"

$sFrom = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")

;$sFilter = "(&(objectCategory=user)(samAccountName="+@USERID+"))"
$sFilter = "(&(objectCategory=user)(samAccountName=*))"

$sScope = "subtree"

$aResults = fnLDAPQuery($sWhat,$sFrom,$sFilter,"displayName ASC",$sScope)

For $x = 0 to UBound($aResults)
" Name: " + $aResults[$x][0] ?
"physicalDeliveryOfficeName: " + $aResults[$x][1] ??
Next

Get $

Function fnLDAPQuery($What,$From,Optional $Filter,Optional $OrderBy,Optional $Scope,Optional $User,Optional $Pswd)
Dim $oCon,$oCMD,$oRS,$sQ,$sF,$sGV,$R,$vP,$aR[0],$nul

If $Scope <> "base" AND $Scope <> "onelevel" AND $Scope <> "subtree" $Scope = "subtree" EndIf

$sQ = "<"+$From+">;"+$Filter+";"+Iif(VarType($What)>8192,Join($What,','),$What)+";"+$Scope

If VarType($What)>8192
For Each $sF in $What $sGV=$sGV+'$'+'oRS.Fields("'+$sF+'").Value,' Next
$sGV=Substr($sGV,1,Len($sGV)-1)
Else
$sGV='$'+'oRS.Fields("'+$What+'").Value'
EndIf

$oCon=CreateObject("ADODB.Connection")
$oCon.Provider = "ADsDSOObject"
$oCon.Properties("Encrypt Password").Value=1
$oCon.Properties("ADSI Flag").Value=1
If $User AND $Pswd
$oCon.Properties("User ID").Value=$User
$oCon.Properties("Password").Value=$Pswd
EndIf
$oCon.Open("Active Directory Provider")

$oCMD=CreateObject("ADODB.Command")
$oCMD.ActiveConnection=$oCon
$oCMD.CommandText=$sQ
$oCMD.Properties("Page Size").Value=1000
$oCMD.Properties("Timeout").Value=30
$oCMD.Properties("Cache Results").Value=0

If $OrderBy="distinguishedName"
$oRS = CreateObject("ADODB.Recordset")
$oRS.CursorLocation=3
$oRS.Sort=$OrderBy
$oRS.Open($sQ,$oCon,0,1,1)
Else
If $OrderBy
$oCMD.Properties("Sort On").Value=$OrderBy
EndIf
$oRS = $oCMD.Execute
EndIf
If @ERROR Exit @ERROR EndIf
If $oRS.BOF AND $oRS.EOF Exit @ERROR EndIf

Do
$nul=Execute('$'+'vP='+$sGV)
$aR[$R]=$vP
$oRS.MoveNext
$R=$R+1
ReDim Preserve $aR[$R]
Until $oRS.EOF
ReDim Preserve $aR[$R-1]
$fnLDAPQuery=$aR
EndFunction


Top
#141682 - 2005-06-15 11:16 PM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
sheesh nevermind I am sorry guys - it does work. For some reason there were AD permissions set on my own user account to where I couldn't manually change my Office field - it was blank. Brain fart. Thanks a ton.
Top
#141683 - 2005-06-16 12:54 AM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
OK last thing. I have it all tied in with my normal script to achieve what I want to achieve. Which variable would I use for this?

I have something like this for example:

$pcname = @wksta
$username = @userid
$department = $?????

Based on the ADquery script it seems that the results would be this $aResults or no? or could I do something like this $fnLDAPQuery.

And then at the insert:

$rs.fields.item("Department").value = $department
Is this as easy as it is?


Edited by DJ Ballistic (2005-06-16 01:08 AM)

Top
#141684 - 2005-06-16 01:29 AM Re: Please help
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
Horray - I figured it out - problems solved. Thanks for the help guys.
Top
Page 3 of 3 <123


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

Who's Online
1 registered (Allen) and 781 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.056 seconds in which 0.028 seconds were spent on a total of 13 queries. Zlib compression enabled.

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