| 
| 
| 
| #75055 - 2003-05-17 04:51 AM  Pre-UDF  EnumAD() |  
| Allen   KiX Supporter
 
       
 Registered:  2003-04-19
 Posts: 4562
 Loc:  USA
 | 
Basically this is a netview for OUs.  I think there is more we could do with this, and was kind of looking for some ideas...
 Let me know.
 
 
 code:Here is a simple example:
 Function EnumAD(optional $ou,optional $filter,optional $detaillevel)Dim $rootdse,$domain,$objects,$container,$OUObject
 $rootdse=getobject("LDAP://RootDSE") ;binds rootdse to local ldap object
 $domain=$rootdse.get("DefaultNamingContext") ;determines local domain
 if $ou<>''
 if right($ou,1)<>','
 $ou=$ou + ','
 endif
 endif
 $container="LDAP://" + $ou + $domain
 $ouobjects = GetObject($container)
 select
 case ucase($filter)="ORGANIZATIONALUNIT"
 $ouobjects.Filter = "OrganizationalUnit","_"
 case ucase($filter)="COMPUTER"
 $ouobjects.Filter = "computer","_"
 case ucase($filter)="GROUP"
 $ouobjects.Filter = "group","_"
 case ucase($filter)="USER"
 $ouobjects.Filter = "user","_"
 endselect
 For Each $OUObject in $ouobjects
 if $objects<>""
 $objects=$objects + '|'
 endif
 select
 case $detaillevel=2
 if ucase($filter)="USER"
 If $OUObject.Class = "user"
 $objects=$objects + ucase($OUObject.ADSPath)
 endif
 else
 $objects=$objects + ucase($OUObject.ADSPath)
 endif
 
 case $detaillevel=1
 if ucase($filter)="USER"
 If $OUObject.Class = "user"
 $objects=$objects + ucase($OUObject.Name)
 endif
 else
 $objects=$objects + ucase($OUObject.Name)
 endif
 
 case 1
 if ucase($filter)="USER"
 If $OUObject.Class = "user"
 $objects=$objects + ucase(substr($OUObject.Name,4))
 endif
 else
 $objects=$objects + ucase(substr($OUObject.Name,4))
 endif
 endselect
 Next
 $EnumAD=split($objects,'|')
 Endfunction
 
 
 break on
 $ouroot="ou=adtest"
 dim $ou
 $OUs=EnumAD($ouroot,"OrganizationalUnit",1)
 for each $ou in $OUs
 for each $computer in EnumAD("$ou,$ouroot","Computer",2)
 if $computer<>""
 ? $computer
 endif
 next
 next
 
 [ 17. May 2003, 05:32: Message edited by: Al_Po ]
 |  
| Top |  |  |  |  
| 
| 
| #75056 - 2003-05-17 04:59 AM  Re: Pre-UDF  EnumAD() |  
| Howard Bullock   KiX Supporter
 
       
   Registered:  2000-09-15
 Posts: 5809
 Loc:  Harrisburg, PA USA
 | 
I have found the when setting the filter using the shortcut arrsy form '$x.Filter = "user",""' worked on the WinNT:// provider but did not work when using the LDAP:// provider.  What is the purpose of the "_" in '$ouobjects.Filter = "group","_"'?
 |  
| Top |  |  |  |  
| 
| 
| #75057 - 2003-05-17 05:09 AM  Re: Pre-UDF  EnumAD() |  
| Allen   KiX Supporter
 
       
 Registered:  2003-04-19
 Posts: 4562
 Loc:  USA
 | 
Howard,
 I happened to see a post by Shawn (I think) and he mentioned that the filter had to be an array, and one way for kixtart to recognize an array is to separate the values with a ",".  The second value is nothing other than a place holder.   I tried just using "" as well as what you described, and as you stated, it didn't work, but with something in that second position, it does work.
 ![[Smile]](images/icons/smile.gif) 
 [ 17. May 2003, 05:33: Message edited by: Al_Po ]
 |  
| Top |  |  |  |  
| 
| 
| #75058 - 2003-05-17 05:14 AM  Re: Pre-UDF  EnumAD() |  
| Howard Bullock   KiX Supporter
 
       
   Registered:  2000-09-15
 Posts: 5809
 Loc:  Harrisburg, PA USA
 | 
As in my other code recently posted you can "Dim $aFilter[0]" then "$adFilter = 'group'" for LDAP://. I find it interesting that the "bogus" text string makes the shortcut way $aFilter = "group","_" work. Thanks for the tip.  ![[Smile]](images/icons/smile.gif)  |  
| Top |  |  |  |  
 Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
 
 | 
| 
 
| 0 registered
and 456 anonymous users online. 
 | 
 |  |