Page 1 of 2 12>
Topic Options
#190788 - 2008-12-03 12:17 AM LDAP Query into array thanks
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Hey Apronk and Kix gurus!
thanks for all yoru help !

Long time to see ;\) I know you the man who can either help me or point me in the direction. This is what I want to do. Remember that program I made for my work well it is working great. The issue is I want to not have to update my array list I made the array variable is called $Branch for net bios names for each PC in our domain. Follow me. Well in our Active Directory we have 4 branch OUs and in the branch OUs we have the OU named Computer. So you have this for example:

4th\Computer ...pcs named ftran1, ftran2, fmsr1, fmsr2 etc.....
8th\Computer ...pcs named emsr1, emsr2, emort1, emort3 etc....
Point\Computer ...pcs named smsr1, smsr2,smsr3, etc....
Plover\Computer...pcs name pmsr1, pmsr2, ect....

in each OU you have their respective netbios names according to AD OU.
So I want a program to reside on a domain controller with Admin domain rights it will have. and pull the names from these OUs into a text file or what have you into an array list $Branch. I want to just click it to update this file into what my program use a file call domain.kix and in there is a list of names that my array is defined by $Branch = "smsr1", "smsr2", "pmsr1", "pmsr2", etc....is this possible?? thanks alot for your help...




Edited by itdaddy (2008-12-04 08:30 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#190789 - 2008-12-03 03:49 AM Re: Glenn help! You the man! [Re: itdaddy]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
While I am not Glenn, You can use the UDF fnLDAPQuery() to generate your array on the fly.

 Code:
 $Batch = fnLDAPQuery('computer','ou=Computer,ou=4th,dc=microsoft,dc=fabrikon,dc=com')
;fnLDAPQuery(WHAT, Optional FROM, Optional FILTER, Optional ORDER BY, Optional SCOPE, Optional USER, Optional PASSWORD)

You can find the udf here http://www.kixtart.org/UDF/UDF_lister.php?what=post&code=142043
_________________________
Today is the tomorrow you worried about yesterday.

Top
#190790 - 2008-12-03 10:53 AM Re: Glenn help! You the man! [Re: Gargoyle]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Just to show a different approach:
 Code:
Dim $OU1, $OU2, $x
$OU1 = GetComps("OU=Computers,OU=branch1,DC=domain,DC=local")
$OU2 = GetComps("OU=Computers,OU=branch2,DC=domain,DC=local")

For Each $x in $OU1
  ;Can list this to a text file too
  ? $x
Next

For Each $x in $OU2
  ;Can list this to a text file too
  ? $x
Next

Function GetComps($strAdsPath)
  Dim $objAdsPath, $obj, $filter[0], $arrComps[]
  $filter[0] = "Computer"
  $objADsPath = GetObject("LDAP://"+$strAdsPath)
  $objAdsPath.filter = $filter
  For Each $obj in $objAdsPath
    ReDim Preserve $arrComps[UBound($arrComps)+1]
    $arrComps[UBound($arrComps)] = $obj.cn
  Next
  $GetComps = $arrComps
EndFunction


You can also then join $OU1 and $OU2 into 1 array, but I figured you would like to have them separate. But if you don't the fnLDAPQuery i the best option here. Also fnLDAPQuery is faster then this solution.

Top
#190791 - 2008-12-03 01:30 PM Re: Glenn help! You the man! [Re: Arend_]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Thanks guys!

I generally use Gargoyle's approach when I want a specific list of objects, since the UDF does most (if not all) of the object filtering. I use Arend's method when I want a larger list - usually when I need a customized filter that LDAPQuery won't provide. This is usually something like machines with specific content in their names, or a combination of OU and name format.

I'd skip the external file generation altogether and simply use an argument to specify the branch you want to query, generating the data as the program is run. I can dump a list of 4500+ computer names from AD in about 2-3 seconds. I do run the resulting array through the Sort and Uniq UDFs to remove any possible dups. (don't ask!)

Question(s) - do you have Sys-Admins at each location?
Do you use AD Sites?
Do you use GPOs?

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190793 - 2008-12-03 03:53 PM Re: Glenn help! You the man! [Re: Glenn Barnas]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
you guys are awesome will try. and I was just trying to get Glenn's attention to say hi! I appreciate you both and your great knowledge. I hope someday I will be as smart as you dudes!

so i add the $Branch code above to my file that needs the $Branch array
and it pulls on the fly the computers that I need in to process right? I can see the elements of the code I need to change. but do i need to
call in or inlude some file that has the UDF? Kixtart doesnt have this build in does it? I need some file in need to call/include in with the $branch UDF statement right?


Glenn
no sys admin at each site only me.
yes we use sites and GPO
-robert


Edited by itdaddy (2008-12-03 04:01 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#190794 - 2008-12-03 03:58 PM Re: Glenn help! You the man! [Re: Gargoyle]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
so gargolye
i can specify a specific OU if I want for that array? $Branch?
Yeah I want that specific OU in certain files. At each site
I have a file called domain.kix but I could easily but the $Branch code you suggested in the main file and have it call the list on the fly. that is what you mean right not make a file just calls that specific OU say
4th\computers and pulls in each PC name right? on the fly?
wow if this is possible wow amazing results will ihave i will no longer
have to update any file it will just be updated when we edit AD haha awewsome. Can you verify i understand you gargoyle thanks so much!
robert;)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#190795 - 2008-12-03 04:14 PM Re: Glenn help! You the man! [Re: itdaddy]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
What Gargoyle means is exactly how I wrote my code.
Only instead of using my GetComps function using fnLDAPQuery.
Both Gargoyle's and my suggestion provide the same output since you would have to use the function 4 times.

Top
#190797 - 2008-12-03 05:34 PM Re: Glenn help! You the man! [Re: Arend_]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Okay let me get this straight. I can put the ldap funct you guys suggeted in a kix file and then call this file say it is ldap1.kix i name it and then at the head of each place i use this file ldap1.kix i say call 'ldap1.kix' in each file i use this ldap function. then i make the program that Apronk made but use the Function fnLDAPQuery() with the same parameters as gargoyle suggested. is this correect??? am i getting it or am i totally lost guys! thanks and I do not ant to put in a text file I want ot just use the arrays on the fly
robert


Edited by itdaddy (2008-12-03 05:35 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#190799 - 2008-12-03 05:36 PM Re: Glenn help! You the man! [Re: itdaddy]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
That should do it \:\)
Top
#190807 - 2008-12-03 06:16 PM Re: Glenn help! You the man! [Re: Arend_]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
What do you think? is this what you mean?
I think so. But I want it to out put the lists to see if it pulls into arrays? you rock Apronk! l;)

 Code:
;******************************************
;Creates array lists of each branch
;by pulling comuter names from each 
;respective OU in an AD domain for
;specific programs to access
;respective $BranchX array variables
;once generated variable hold value in RAM
;to be used by programs.
;******************************************


Dim $Branch1, $Branch2, $Branch3, $Branch4
;fnLDAPQuery(WHAT, Optional FROM, Optional FILTER, Optional ORDER BY, Optional SCOPE, Optional USER, Optional PASSWORD)

$Branch1 = fnLDAPQuery('computer','ou=Computer,ou=4th,dc=microsoft,dc=fabrikon,dc=com')
$Branch2 = fnLDAPQuery('computer','ou=Computer,ou=8th,dc=microsoft,dc=fabrikon,dc=com')
$Branch3 = fnLDAPQuery('computer','ou=Computer,ou=plov,dc=microsoft,dc=fabrikon,dc=com')
$Branch4 = fnLDAPQuery('computer','ou=Computer,ou=Stevens,dc=microsoft,dc=fabrikon,dc=com')

;display each $Branch variable array list to test to see if works
For Each $x in $Branch1
  ;Display array list as test
  ? $x
Next

For Each $x in $Branch2
  ;Display array list as test
  ? $x
Next

For Each $x in $Branch3
  ;Display array list as test
  ? $x
Next

For Each $x in $Branch4
  ;Display array list as test
  ? $x
Next

Function fnLDAPQuery($What,Optional $From,Optional $Filter,Optional $OrderBy,Optional $Scope,
    Optional $User,Optional $Pswd)
    
    Dim $oCon,$oCMD,$oRS,$sQ,$aR,$C,$R
    
    $sQ="<"+Iif($From="","LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext"),
        $From)+">;"+$Filter+";"+Iif(VarType($What)>8192,Join($What,','),$What)+";"+
        Iif($Scope<>"base" AND $Scope<>"onelevel","subtree",$Scope)
    
    $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 InStr($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
    
    $aR = $oRS.GetRows()
    Dim $aFR[Ubound($aR,2),Ubound($aR,1)]
    For $R=0 to Ubound($aR,2)
        For $C=0 to Ubound($aR,1)
            $aFR[$R,$C]=$aR[$C,$R]
        Next
    Next
    
    $fnLDAPQuery=$aFR
EndFunction








Edited by Benny69 (2008-12-04 04:43 AM)
Edit Reason: Added Code Tags
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#190809 - 2008-12-03 06:23 PM Re: Glenn help! You the man! [Re: itdaddy]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Yeah, but then with code tags ;\)
Top
#190810 - 2008-12-03 06:46 PM Re: Glenn help! You the man! [Re: Arend_]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Apronk,
I hate asking more questions but this is what I have. I have a DomainAD.cmd file with kix32 DomainAD.kix (name of file below) to run this
and nothing outputs to screen? I even have a pause at end of my cmd file.
What did I do wrong? I am runnin this on a file server with domain rights?
Is the order of my ldap query right (the parameters?) I use funny as a fake domain name for security but this is how it goes:
the levels are funny.priv then funny ou, then branch name then Computers final OU with the list of computers inside? is that right order?
 Code:
 

Dim $Branch1, $Branch2, $Branch3, $Branch4
;fnLDAPQuery(WHAT, Optional FROM, Optional FILTER, Optional ORDER BY, Optional SCOPE, Optional USER, Optional PASSWORD)

$Branch1 = fnLDAPQuery('SRV-DC1','ou=funny,ou=ForthAve,ou=Computers,dc=microsoft,dc=funny,dc=priv')
$Branch2 = fnLDAPQuery('SRV-DC1','ou=funny,ou=EighthSt,ou=Computers,dc=microsoft,dc=funny,dc=priv')
$Branch3 = fnLDAPQuery('SRV-DC1','ou=funny,ou=PostRd,ou=Computers,dc=microsoft,dc=funny,dc=priv')
$Branch4 = fnLDAPQuery('SRV-DC1','ou=funny,ou=ParkDr,ou=Computers,dc=microsoft,dc=funny,dc=priv')
;*****************************Display Test ****************************************************
For Each $x in $Branch1
  ;Display array list as test
  ? $x
Next

For Each $x in $Branch2
  ;Display array list as test
  ? $x
Next

For Each $x in $Branch3
  ;Display array list as test
  ? $x
Next

For Each $x in $Branch4
  ;Display array list as test
  ? $x
Next

;***********************LDAP Function ******************************************************

Function fnLDAPQuery($What,Optional $From,Optional $Filter,Optional $OrderBy,Optional $Scope,
    Optional $User,Optional $Pswd)
    
    Dim $oCon,$oCMD,$oRS,$sQ,$aR,$C,$R
    
    $sQ="<"+Iif($From="","LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext"),
        $From)+">;"+$Filter+";"+Iif(VarType($What)>8192,Join($What,','),$What)+";"+
        Iif($Scope<>"base" AND $Scope<>"onelevel","subtree",$Scope)
    
    $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 InStr($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
    
    $aR = $oRS.GetRows()
    Dim $aFR[Ubound($aR,2),Ubound($aR,1)]
    For $R=0 to Ubound($aR,2)
        For $C=0 to Ubound($aR,1)
            $aFR[$R,$C]=$aR[$C,$R]
        Next
    Next
    
    $fnLDAPQuery=$aFR
EndFunction

_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#190811 - 2008-12-03 06:49 PM Re: Glenn help! You the man! [Re: itdaddy]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Do I need password and user name if ran off of a file server with Domain admin rights???? and if so what is the way to do it? I now you add them to the parameters of the ldap query function but what are the tags (for example (ou=funny,dc=priv,user=administrator,password=getrunning) ??? i dont know how to label the user name and password in the paramaters if i need it but you would think if ran off or file server with domain admin login? it would just run. all my other programs run? it just thinks and no output?? what am i doing wrong? it looks right? is dc=microsoft wrong?? what do i put there? looks right? does the order or the ou/dc correct from highest
funny.priv
funny (ou)
ForthAve (ou)
Computers(ou)
Users(ou)
EighthSt(ou)
Computers(ou)
Users(ou)
ParkDr(ou)
Computers(ou)
Users(ou)
PostRd(ou)
Computers(ou)
Users(ou)

This is the levels of domain and ous.


Edited by itdaddy (2008-12-03 06:53 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#190812 - 2008-12-03 06:49 PM Re: Glenn help! You the man! [Re: Arend_]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
This will be the working code:
 Code:
;******************************************
;Creates array lists of each branch
;by pulling comuter names from each 
;respective OU in an AD domain for
;specific programs to access
;respective $BranchX array variables
;once generated variable hold value in RAM
;to be used by programs.
;******************************************


Dim $Branch1, $Branch2, $Branch3, $Branch4
;fnLDAPQuery(WHAT, Optional FROM, Optional FILTER, Optional ORDER BY, Optional SCOPE, Optional USER, Optional PASSWORD)
$Branch1 = fnLDAPQuery('Name','LDAP://ou=Computer,ou=4th,dc=microsoft,dc=fabrikon,dc=com','(&(objectClass=Computer)(Name=*))')
$Branch2 = fnLDAPQuery('Name','LDAP://ou=Computer,ou=8th,dc=microsoft,dc=fabrikon,dc=com','(&(objectClass=Computer)(Name=*))')
$Branch3 = fnLDAPQuery('Name','LDAP://ou=Computer,ou=plov,dc=microsoft,dc=fabrikon,dc=com','(&(objectClass=Computer)(Name=*))')
$Branch4 = fnLDAPQuery('Name','LDAP://ou=Computer,ou=Stevens,dc=microsoft,dc=fabrikon,dc=com','(&(objectClass=Computer)(Name=*))')

For Each $x in $Branch1
;Display array list as test
? "1:"+$x
Next

For Each $x in $Branch2
;Display array list as test
? "2:"+$x
Next

For Each $x in $Branch3
;Display array list as test
? "3:"+$x
Next

For Each $x in $Branch4
;Display array list as test
? "4:"+$x
Next

Function fnLDAPQuery($What,Optional $From,Optional $Filter,Optional $OrderBy,Optional $Scope,Optional $User,Optional $Pswd)
  Dim $oCon,$oCMD,$oRS,$sQ,$aR,$C,$R
  $sQ="<"+Iif($From="","LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext"),$From)+">;"+$Filter+";"+Iif(VarType($What)>8192,Join($What,','),$What)+";"+Iif($Scope<>"base" AND $Scope<>"onelevel","subtree",$Scope)
  $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 InStr($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
    
  $aR = $oRS.GetRows()
  Dim $aFR[Ubound($aR,2),Ubound($aR,1)]
  For $R=0 to Ubound($aR,2)
    For $C=0 to Ubound($aR,1)
       $aFR[$R,$C]=$aR[$C,$R]
    Next
  Next
  $fnLDAPQuery=$aFR
EndFunction

Top
#190813 - 2008-12-03 06:50 PM Re: Glenn help! You the man! [Re: Arend_]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
I assumed Gargolye's input vars were correct, but ASSUME makes an ASS out of U and ME ;\)
Top
#190815 - 2008-12-03 08:46 PM Re: Glenn help! You the man! [Re: Arend_]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
apronk
what goes in the Name variable? is it the Domain Computer with AD on it?
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#190816 - 2008-12-03 08:58 PM Re: Glenn help! You the man! [Re: itdaddy]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Apronk

like this? wasnt sure what whent in Computer or name if it was just or did the ou Computers go there? and I put the AD dc in place of name is this allw rong? I am confused on what goes in what place
remeber the ad hierarchy goes like ths
funnycu.priv
funncu
forthave
Computers
(repeat branch names and ou computers)


 Code:
 

Dim $Branch1, $Branch2, $Branch3, $Branch4
;fnLDAPQuery(WHAT, Optional FROM, Optional FILTER, Optional ORDER BY, Optional SCOPE, Optional USER, Optional PASSWORD)
$Branch1 = fnLDAPQuery('srv-dc1','LDAP://ou=Computers,ou=forthAve,dc=microsoft,dc=funnycu,dc=priv','(&(objectClass=Computers)(srv-dc1=*))')
$Branch2 = fnLDAPQuery('srv-dc1','LDAP://ou=Computers,ou=EighthSt,dc=microsoft,dc=funnycu,dc=priv','(&(objectClass=Computers)(srv-dc1=*))')
$Branch3 = fnLDAPQuery('srv-dc1','LDAP://ou=Computers,ou=PostRd,dc=microsoft,dc=funnycu,dc=priv','(&(objectClass=Computers)(srv-dc1=*))')
$Branch4 = fnLDAPQuery('srv-dc1','LDAP://ou=Computers,ou=PostRd,dc=microsoft,dc=funnycu,dc=priv','(&(objectClass=Computers)(srv-dc1=*))')

For Each $x in $Branch1
;Display array list as test
? "1:"+$x
Next

For Each $x in $Branch2
;Display array list as test
? "2:"+$x
Next

For Each $x in $Branch3
;Display array list as test
? "3:"+$x
Next

For Each $x in $Branch4
;Display array list as test
? "4:"+$x
Nex


_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#190817 - 2008-12-03 09:09 PM Re: Glenn help! You the man! [Re: itdaddy]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
apronk
Here is the exact code I am using expect for bogous domain name funncu.
It runs with no errors but no pull for AD?? what did I do wrong
i have in a cmd file kix32 DomainAD.kix and runs but no output and no errors. Do I have some of the names wrong??? sorry to be so stupid
but I am really trying..



 Code:
 

Dim $Branch1, $Branch2, $Branch3, $Branch4
;fnLDAPQuery(WHAT, Optional FROM, Optional FILTER, Optional ORDER BY, Optional SCOPE, Optional USER, Optional PASSWORD)
$Branch1 = fnLDAPQuery('srv-dc1','LDAP://ou=funncu,ou=ForthAve,ou=Computers,dc=microsoft,dc=funncu,dc=priv','(&(objectClass=Computer)(srv-dc1=*))')
$Branch2 = fnLDAPQuery('srv-dc1','LDAP://ou=funncu,ou=EighthSt,ou=Computers,dc=microsoft,dc=funncu,dc=priv','(&(objectClass=Computer)(srv-dc1=*))')
$Branch3 = fnLDAPQuery('srv-dc1','LDAP://ou=funncu,ou=PostRd,ou=Computers,dc=microsoft,funncu,dc=priv','(&(objectClass=Computer)(srv-dc1=*))')
$Branch4 = fnLDAPQuery('srv-dc1','LDAP:/ou=funncu,ou=ParkDr,ou=Computers,dc=microsoft,dc=funncu,dc=priv','(&(objectClass=Computer)(srv-dc1=*))')

For Each $x in $Branch1
;Display array list as test
? "1:"+$x
Next

For Each $x in $Branch2
;Display array list as test
? "2:"+$x
Next

For Each $x in $Branch3
;Display array list as test
? "3:"+$x
Next

For Each $x in $Branch4
;Display array list as test
? "4:"+$x
Next

Function fnLDAPQuery($What,Optional $From,Optional $Filter,Optional $OrderBy,Optional $Scope,Optional $User,Optional $Pswd)
  Dim $oCon,$oCMD,$oRS,$sQ,$aR,$C,$R
  $sQ="<"+Iif($From="","LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext"),$From)+">;"+$Filter+";"+Iif(VarType($What)>8192,Join($What,','),$What)+";"+Iif($Scope<>"base" AND $Scope<>"onelevel","subtree",$Scope)
  $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 InStr($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
    
  $aR = $oRS.GetRows()
  Dim $aFR[Ubound($aR,2),Ubound($aR,1)]
  For $R=0 to Ubound($aR,2)
    For $C=0 to Ubound($aR,1)
       $aFR[$R,$C]=$aR[$C,$R]
    Next
  Next
  $fnLDAPQuery=$aFR
EndFunction

   





Edited by itdaddy (2008-12-03 09:12 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#190818 - 2008-12-03 09:15 PM Re: Glenn help! You the man! [Re: itdaddy]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
I think you could also use an array for your branches.

(untested and I've never used fnLDAPQuery... )
 Code:
Dim $Branches[3],$branch,$i,$x

$Branches[0]=fnLDAPQuery('computer','ou=Computer,ou=4th,dc=microsoft,dc=fabrikon,dc=com')
$Branches[1]=fnLDAPQuery('computer','ou=Computer,ou=8th,dc=microsoft,dc=fabrikon,dc=com')
$Branches[2]=fnLDAPQuery('computer','ou=Computer,ou=plov,dc=microsoft,dc=fabrikon,dc=com')
$Branches[3]=fnLDAPQuery('computer','ou=Computer,ou=Stevens,dc=microsoft,dc=fabrikon,dc=com')

;display each $Branch variable array list to test to see if works
For Each $branch in $branches
  $i=$i+1
  For each $x in $branch
    ;Display array list as test
    ? "" + $i + ":" + $x
  Next
Next


Edited by Allen (2008-12-03 09:23 PM)

Top
#190819 - 2008-12-04 01:15 AM Re: Glenn help! You the man! [Re: Allen]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
 Code:
$Batch = FnLDAPQuery("Name","cn=Computer,ou=4th","(objectClass=computer)",,"SUBTREE" )


Sorry it has taken so long to respond. Your first variable is what Value from the LDAP object you want to return, second variable is where to search (I believe you can leave the root off of this, but you may need to add it). In My AD enviroment the computers are all in a container not an OU. The third variable tells it what type of object class you are looking for so that you can filter out unwanted results and so on and so forth.

If you are unsure of what all of the AD properties are get a good LDAP Browser (there are lots of free ones out there), it will help you many times over.
_________________________
Today is the tomorrow you worried about yesterday.

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 611 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.077 seconds in which 0.025 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