Page 1 of 1 1
Topic Options
#160240 - 2006-04-03 04:43 PM Enumerate OU's (Filter Method fussy)
Kelly_Dyjur Offline
Fresh Scripter

Registered: 2005-04-05
Posts: 21
I want to list all sub-ou's in an OU. I found this VBS on the script center:
Code:

Set objOU = GetObject("LDAP://ou=one,ou=two,dc=corp,dc=ads")
objOU.Filter = Array("organizationalUnit")
strList = "Select an Organizational Unit:"
For Each objChild In objOU
strList = strList & vbCrLf & objChild.ou
Next
strSelect = InputBox(strList, "MyProgram")



And came up with this KiXtart equivalent:

Code:
  

$Filter[0] = "organizationalUnit"

$objOU = GetObject("LDAP://ou=one,ou=two,dc=corp,dc=ads")
$objOU.Filter = $Filter

For Each $objChild in $objOU
? $objChild.name
Next




When I run my KiXtart though, it returns everything in the OU, Sub-OU's, and computers in that OU as well. So it appears as though I am not setting up the filter properly. Can anyone see an obvious error in this small snippet? I don't know the filter method all that well, or why I would be using it with an array

Top
#160241 - 2006-04-03 04:48 PM Re: Enumerate OU's (Filter Method fussy)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
objOU.Filter = "organizationalUnit",""
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160242 - 2006-04-03 04:50 PM Re: Enumerate OU's (Filter Method fussy)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
or:
objOU.Filter = Split("organizationalUnit")
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160243 - 2006-04-03 04:57 PM Re: Enumerate OU's (Filter Method fussy)
Kelly_Dyjur Offline
Fresh Scripter

Registered: 2005-04-05
Posts: 21
I changed that, and now I am getting no return. Here is the modified code:
Code:

Break on

$Filter[0] = "organizationalUnit",""

$objOU = GetObject("LDAP://ou=winops ab,ou=server accounts,dc=corp,dc=ads")
$objOU.Filter = $Filter

For Each $objChild in $objOU
? $objChildname.name
Next



Edited by Kelly_Dyjur (2006-04-03 04:58 PM)

Top
#160244 - 2006-04-03 05:01 PM Re: Enumerate OU's (Filter Method fussy)
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Change this:
$Filter[0] = "organizationalUnit",""
to this:
$Filter = "organizationalUnit",""

Top
#160245 - 2006-04-03 05:04 PM Re: Enumerate OU's (Filter Method fussy)
Kelly_Dyjur Offline
Fresh Scripter

Registered: 2005-04-05
Posts: 21
Allen, I tried that, but I still return no sub-OU's.
Top
#160246 - 2006-04-03 05:37 PM Re: Enumerate OU's (Filter Method fussy)
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL

Code:

$ldap="LDAP://"+@domain+"/"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")
$ou = EnumOUs($ldap, 'computer')
for each $item in split($ou,'|')
? $item
next



Function EnumOUs($LDAP, $Filter)
dim $aFilter[0], $pos, $objOU, $i, $j

if $Filter <> 'user'
$Filter = 'computer'
endif
$objOU = GetObject($LDAP)
if VarTypeName($objOU)='Object'
$aFilter[0] = $Filter
$objOU.Filter = $aFilter
for each $item in $objOU
if $item.class = $Filter
$i = $LDAP
endif
next
$aFilter[0] = "organizationalUnit"
$objOU.Filter = $aFilter
for each $item in $objOU
$Name = $item.Name
$pos = instrrev($LDAP,"/")
$DN = Left($LDAP,$pos) + $Name + ", " + substr($LDAP, $pos+1)
$j = EnumOUs($DN, $Filter)
if $j
$i = iif($i,$i +"|"+ $j,$j)
endif
next
endif
$EnumOUs = $i
Endfunction

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#160247 - 2006-04-03 05:53 PM Re: Enumerate OU's (Filter Method fussy)
Kelly_Dyjur Offline
Fresh Scripter

Registered: 2005-04-05
Posts: 21
Thanks Radimus, I had seen that UDF in my searches but didn't incorporate it. It works now. I actually was using WSHPipe with DSQuery and it worked really good, but I'm trying to design a GUI for my tool and WSHPipe kicks open a console window, so now I'm going through the script and removing all of them.

Thanks again all, and Radimus, love the sig.

Top
#160248 - 2006-04-03 06:42 PM Re: Enumerate OU's (Filter Method fussy)
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
You could also borrow stuff from my AD Explorer...

http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=144246&an=0&page=0#144246

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
0 registered and 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.069 seconds in which 0.034 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