#160240 - 2006-04-03 04:43 PM
Enumerate OU's (Filter Method fussy)
|
Kelly_Dyjur
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
|
|
|
|
#160243 - 2006-04-03 04:57 PM
Re: Enumerate OU's (Filter Method fussy)
|
Kelly_Dyjur
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
|
|
|
|
#160245 - 2006-04-03 05:04 PM
Re: Enumerate OU's (Filter Method fussy)
|
Kelly_Dyjur
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
   
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
|
|
Top
|
|
|
|
#160247 - 2006-04-03 05:53 PM
Re: Enumerate OU's (Filter Method fussy)
|
Kelly_Dyjur
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.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 657 anonymous users online.
|
|
|