Page 1 of 1 1
Topic Options
#70284 - 2002-09-26 09:07 PM ENUMGROUP Question
ElGuapo Offline
Starting to like KiXtart

Registered: 2002-06-19
Posts: 100
I want to get all users in an ou, check their group membership and manipulate some of their properties based upon group membership.

While I can read the members of the OU, I cannot get the checking of their group membership to work. Can you help me out please?

$ou = olegetobject(0,"LDAP://OU=texas,ou=sales,DC=mycompany,DC=net")
$enum = oleenumobject($ou)
$object = oleenumobject($ou,$enum)
while $object
if olegetproperty($object,"class") = "user"
$name = olegetproperty($object,"name")
$group = ""
$groupcount = 0
do
$group = ENUMGROUP($groupcount)

until len($group) = 0
endif
$object = oleenumobject($ou,$enum)
loop
exit

Top
#70285 - 2002-09-26 09:08 PM Re: ENUMGROUP Question
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
what version of Kix...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#70286 - 2002-09-26 09:13 PM Re: ENUMGROUP Question
ElGuapo Offline
Starting to like KiXtart

Registered: 2002-06-19
Posts: 100
3.61 in a pure Windows 2000 domain.
Top
#70287 - 2002-09-26 09:17 PM Re: ENUMGROUP Question
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I would recommend upgrading to 4.02 or better. The COM in the newer version is much better and would make this a piece of cake.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70288 - 2002-09-26 09:25 PM Re: ENUMGROUP Question
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
4.02 or wait for 4.12 to go gold.

skip 4.10 and 4.11
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#70289 - 2002-09-26 09:26 PM Re: ENUMGROUP Question
ElGuapo Offline
Starting to like KiXtart

Registered: 2002-06-19
Posts: 100
I'll work on upgrading, but don't see that happening right away. Any help available until then?
Top
#70290 - 2002-09-26 09:27 PM Re: ENUMGROUP Question
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Enumgroup only enumerates the groups for the current user.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70291 - 2002-09-26 09:31 PM Re: ENUMGROUP Question
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
there are really only a few people here that a real grip on olefunction...

the COM in 4.02+ has taken off like wildfire.

see the function Groupmembers() in the UDF forum for a great example in the direction you need.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#70292 - 2002-09-26 09:31 PM Re: ENUMGROUP Question
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
It sounds to me like you are running this script from your desktop to collect information. You can install a newer version on your computer only to execute this code.

code:
$ou = GetObject("LDAP://DomainName/OU=texas,ou=sales,DC=mycompany,DC=net")
Dim $Filter[0]
$Filter[0] = "user"
$ou.Filter = $Filter
for each $account in $ou
$name = $account.Name
$groups = $account.groups
foreach $group in $groups
? $group.Name
next
next

{edit} Added "Name" property to " ? group.Name"

Some additional code you could leverage.
code:
;FUNCTION         GetGroups()
;
;AUTHOR Howard A. Bullock (habullock@comcast.net)
;
;ACTION Retrieves groups to which the specified account is a member.
;
;SYNTAX GetGroups($Domain, $Account, optional $Suppress)
;
;PARAMETERS $Domain (Required) - String value
; $Account (Required) - String value
; $Suppress (Optional) - Integer value [0|1] Default = 0
;
;REMARKS When a non-zero value is supplied for $Suppress, The screen output
; is omitted.
;
; Note: ADS_GROUP_TYPE_SECURITY_ENABLED is not shown using WinNT://
; only security groups exists in NT4 (WinNT://)
;
;RETURNS Two-Dimensional Array.
; 0,x = Group Name
; 1,x = Group Type
; x = number of groups
;
;DEPENDENCIES KiXtart 4.11
;
;EXAMPLES $Groups = GetGroups("Domain", @wksta + "$$") for the computer account
; $Groups = GetGroups("Domain", "User1") for a user account
;
Function GetGroups($Domain, $Account, optional $Suppress)

; Group Types
; ADS_GROUP_TYPE_GLOBAL_GROUP = 0x00000002,
; ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP = 0x00000004,
; ADS_GROUP_TYPE_LOCAL_GROUP = 0x00000004,
; ADS_GROUP_TYPE_UNIVERSAL_GROUP = 0x00000008,
; ADS_GROUP_TYPE_SECURITY_ENABLED = 0x80000000

;

Dim $Groups[1,0], $i, $x, $Type[8]
$Type[2] = "GLOBAL_GROUP"
$Type[4] = "LOCAL_GROUP"
$Type[8] = "UNIVERSAL_GROUP"
$oAccount=getobject("WinNT://$Domain/$Account,user")

$x = -1
For Each $group In $oAccount.Groups
$x = $x + 1
ReDim Preserve $Groups[1,$x]
; Class is always 'Group'
; $class = $group.Class
$Groups[0,$x] = $group.Name
$Groups[1,$x] = $Type[$group.groupType]
Next

$GetGroups = $Groups
if not $Suppress
$x = ubound($Groups,2)
? $Domain + "\" + $Account + " is a member of " + ($x+1) + " groups."
For $i=0 to $x
? " '" + $Groups[0,$i] + "' (" + $Groups[1,$i] + ")"
Next
Endif
EndFunction



[ 27. September 2002, 00:03: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70293 - 2002-09-26 09:38 PM Re: ENUMGROUP Question
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I'd modify getgroups() a bit...

i'd make $domain optional, and put a 'if not $domain $domain=@ldomain endif' in it.

Just to make 1 less parameter for those that only have 1 domain to work with.

Other than that, it looks much tighter than GroupMembers()

It is going into my UDF toolbox... :-)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#70294 - 2002-09-26 09:46 PM Re: ENUMGROUP Question
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Radimus, good suggestion. I will incorporate it and update the copy in the UDF Library in the next couple days.

Also I do not know if the WinNT:// provider can get the Universal groups as I do not have a native mode W2K domain yet. This may have to be adjusted to use LDAP://. This would require the use of TranslateName() UDF if you only had the netbios Domain name and an account.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70295 - 2002-09-26 09:53 PM Re: ENUMGROUP Question
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
and not to be nit picky about it, I'd also pull out the $suppress/display section.

I prefer to make function single purpose only...
but perhaps make a second function to handle the display of the groups if necessary.

But I can see how and why you included it... I would have probably built it that way myself.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#70296 - 2002-09-26 10:12 PM Re: ENUMGROUP Question
ElGuapo Offline
Starting to like KiXtart

Registered: 2002-06-19
Posts: 100
HB, Thank you for the ideas and suggestions. I installed kix 411 on my desktop (great idea).

The code you suggested works for name but group returns only empty fields. What am I doing wrong?

BREAK ON
$ou = GetObject("LDAP://mycompany.com/ou=texas,ou=sales,DC=mycompany,DC=com")
Dim $Filter[0]
$Filter[0] = "user"
$ou.Filter = $Filter
for each $account in $ou
$name = $account.name
? "name = $name"
$groups = $account.groups
for each $group in $groups
? "group = $group"
next
next

Top
#70297 - 2002-09-26 10:23 PM Re: ENUMGROUP Question
ElGuapo Offline
Starting to like KiXtart

Registered: 2002-06-19
Posts: 100
Figured it out. Thanks to all.

Dim $Filter[0]
$Filter[0] = "user"
$ou.Filter = $Filter
for each $account in $ou
$name = $account.name
? "name = $name"
$groups = $account.groups
for each $group in $groups
$groupname = $group.name
?"groupname = $groupname"
IF $groupname = "TxSales"
?"YES"
ENDIF
next
next

Top
#70298 - 2002-09-26 11:43 PM Re: ENUMGROUP Question
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You want to use KiXtart 4.12 beta 1 since KiXtart 4.10 and 4.11 have some problems with COM which has been fixed in 4.12 beta 1.

[ 26. September 2002, 23:52: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.067 seconds in which 0.026 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