#85572 - 2002-05-02 05:30 PM
Re: Enumerate all users in AD
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You can also use the filter. code:
$DomObj = getobject("WinNT://dss_test,domain") $DomObj.filter = "user","" for each $user in $DomObj ? $user.name next
|
|
Top
|
|
|
|
#85573 - 2002-05-02 06:31 PM
Re: Enumerate all users in AD
|
jtokach
Seasoned Scripter
   
Registered: 2001-11-15
Posts: 513
Loc: PA, USA
|
Thanks! Ya know what though, I expected to see an increase in time with your version, but it seems the same? Anyhow, I now have bigger problems...
We have +30,000 users on our domain. The list above takes 30 seconds to display. I need only to find users who belong to groups with the prefix abc. (i.e. abc.accounting, abc.purchasing)
This works but would probably take 30-45 minutes to develop a list. Any suggestions on improving performance?
code:
Break On $DomObj = getobject("WinNT://@ldomain,domain") $DomObj.filter = "user","" For Each $User in $DomObj For Each $Group In $User.Groups If Left($Group.name,3)="abc" Goto Pass EndIf Next Goto Fail :Pass ? $user.name :Fail Next
I'm not familiar with the possiblities of the filter method, this is most likely a good starting point though... -Jim
_________________________
-Jim
...the sort of general malaise that only the genius possess and the insane lament.
|
|
Top
|
|
|
|
#85574 - 2002-05-02 06:53 PM
Re: Enumerate all users in AD
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
have a go with this.
code:
$domain = getobject("WinNT://@ldomain")
$domain.filter = "group",""
for each $group in $domain if substr($group.name,1,3) = "abc" ? $group.name + ".." for each $user in $group.members ? $user.name next endif next
if these are global groups and if you have local groups in the global groups, then the local groups will be returned in the $user object as well.
Use $user.class to filter out only user accounts.
Bryce [ 02 May 2002, 18:57: Message edited by: Bryce ]
|
|
Top
|
|
|
|
#85577 - 2002-05-02 07:49 PM
Re: Enumerate all users in AD
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
here ya go.
this should give you an array called $userlist, this array will be a list of all the users who are in your abc* groups with no duplicates.
code:
break on
$domain = getobject("WinNT://@ldomain")
Dim $userlist[5] $i = 0
$domain.filter = "group",""
for each $group in $domain if substr($group.name,1,3) = "abc" for each $user in $group.members if $user.class = "user" for each $name in $userlist if $name = $user.name $flag = 1 endif next if $flag <> 1 $userlist[$i] = $user.name $i = $i + 1 if ubound($userlist) = $i-1 redim preserve $userlist[ubound($userlist) + 5] endif else $flag = 0 endif endif next endif next
redim preserve $userlist[$i-1]
for each $name in $userlist ? $name next
|
|
Top
|
|
|
|
#85579 - 2002-05-03 12:00 AM
Re: Enumerate all users in AD
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
Why not break as soon as the user is found in the list ?
I have taken the liberty to make some small changes in Bryce's script
This should perform even better:code:
break on $domain = getobject("WinNT://@ldomain") Dim $userlist[5] $i = 0 $domain.filter = "group","" for each $group in $domain if substr($group.name,1,3) = "abc" for each $user in $group.members if $user.class = "user" $j = 0 $NotInList = 1 While $j <= $i And $NotInList if $userlist[$j] = $user.name $NotInList = 0 ; User found, stop searching endif Loop if $NotInList $userlist[$i] = $user.name $i = $i + 1 if ubound($userlist) = $i-1 redim preserve $userlist[ubound($userlist) + 5] endif endif endif next endif next redim preserve $userlist[$i-1] for each $name in $userlist ? $name next
-Erik
|
|
Top
|
|
|
|
#85580 - 2002-06-24 11:25 AM
Re: Enumerate all users in AD
|
Mark Bennett
Getting the hang of it
Registered: 2001-10-10
Posts: 70
|
I want to filter by a specific AD container. I have had a quick play around but can't work out the filter syntax. Can anyone help?
Thanks, Mark
|
|
Top
|
|
|
|
#85581 - 2002-06-25 01:04 PM
Re: Enumerate all users in AD
|
Mark Bennett
Getting the hang of it
Registered: 2001-10-10
Posts: 70
|
Sorted - If I had spent some more time researching (as I did yesterday afternoon), I would have found the code below sooner! Have included the code in case someone else goes looking for it.
code:
$domain = GetObject("WinNT://@LDOMAIN") $domain.filter = "group","" For Each $group in $domain If SubStr($group.name,1,31) = "Software - Office Tools" ? $group.name + ".." For Each $user in $group.members $1 = $user.name Shell '%COMSPEC% /C net group "Software - Office Tools" $1 /delete /domain' ? " $1 " Color g+/n "Updated" Next EndIf Next
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 476 anonymous users online.
|
|
|