#111076 - 2003-12-30 06:03 PM
Who belongs to this group? Using AD
|
marguz
Fresh Scripter
Registered: 2002-10-29
Posts: 19
Loc: Illinois
|
Hello, I've been trying to get access to some info in Active Directory. The info in question would be to list all users that are part of a given group, so I need to query a given group for the info. I've tried using some example scripts listed here, but I really don't understand where I can find the info on the proper function calls to use.
Can someone please give an example on how to do this using the "LDAP" thing, and also point me in the direction on where to read-up on using Kixtart and AD.
TIA Mark
|
|
Top
|
|
|
|
#111079 - 2003-12-30 07:15 PM
Re: Who belongs to this group? Using AD
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
Code:
$groupname = 'some group' $obj = GetObject("WinNT://"+@domain+"/"+$groupname+",group") IF $obj for each $user in $obj.members ? $user.name next $obj = 0 ENDIF
|
|
Top
|
|
|
|
#111080 - 2003-12-30 07:47 PM
Re: Who belongs to this group? Using AD
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
and the same thing in UDF format:
Code:
break on
for each $name in EnumGroup('somegroup') ? $name endif
Code:
Function EnumGroup($group, Optional $Domain) DIM $users, $obj if not $domain $domain = @domain endif $obj = GetObject("WinNT://"+$domain+"/"+$group+",group") IF not $obj exit 1 endif for each $user in $obj.members $users=$users + '|' + $user.name next $obj = 0 $EnumGroup = split(substr($users,2),'|') EndFunction
|
|
Top
|
|
|
|
#111083 - 2003-12-31 02:44 AM
Re: Who belongs to this group? Using AD
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
so call translatename() to get the ldap string, and pass it into a modified UDF like what I provided, which only returns the CN as elements in an array.
the only "problem" with using AD/LDAP is that very often you only need the 'simplest' form of the result.
In any case they both work
but we have apparently lost our poster...
|
|
Top
|
|
|
|
#111084 - 2003-12-31 04:16 AM
Re: Who belongs to this group? Using AD
|
marguz
Fresh Scripter
Registered: 2002-10-29
Posts: 19
Loc: Illinois
|
No, I'm here ;-) One of my Citrix boxes stoped it's IMA service and BLA, BLA, BLA... Bad Day 
Thanks to all of you for the replies. I've search this site for "LDAP" but really could not find what I wanted (or maybe I just did not understand what the code would do ) But I really like to sample code I got in the replies, and I will be going over to MSDN.
sealeopard, you listed code that was adopted for Kixtart. Is there a HowTo on what gets replaced with what?
Very nice and helpful forum. Mark
|
|
Top
|
|
|
|
#111087 - 2003-12-31 10:30 AM
Re: Who belongs to this group? Using AD
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
Here is an example to show all members of a specified group within an OU named Groups
You need to supply your real path to the container and the name of the group to check. Then from a command console run KIX32.EXE THIS_SCRIPT.KIX and you should get back what you're looking for.
break on dim $iRC $iRC=setoption('Explicit','on') $iRC=setoption('NoVarsInStrings','on')
ListGroupMembers('GRAPHICS')
function ListGroupMembers($Group) dim $CheckGroup,$Member $CheckGroup = getobject('LDAP://CN='+$Group+',ou=Groups,dc=mycompany,dc=com') for each $Member in $CheckGroup.members ? 'Members of: ' +$Group+' '+$member.SamAccountName+' '+$member.fullname next endfunction |
|
|
Top
|
|
|
|
#111088 - 2003-12-31 03:48 PM
Re: Who belongs to this group? Using AD
|
marguz
Fresh Scripter
Registered: 2002-10-29
Posts: 19
Loc: Illinois
|
OK, The groups will be user input (TA.TIMEKEEPER for example), the domain is global.shsystem.org
I'm running Kixtart 4.22 and I'm one of the Domain Admins.
Mark
|
|
Top
|
|
|
|
#111089 - 2003-12-31 06:06 PM
Re: Who belongs to this group? Using AD
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
Doc, not sure if you need this, but I ran into the filter problem a while back. I searched and searched and finally stumbled across some sample code to help sort out the computers from the users. The snipet below is just creating an array if the Filter defined is "User" and then checks the "class" of the object to determine if it is a computer or user.
Code:
if ucase($filter)="USER" If $OUObject.Class = "user" $objects=$objects + ucase($OUObject.Name) endif endif
|
|
Top
|
|
|
|
#111091 - 2004-01-02 02:46 AM
Re: Who belongs to this group? Using AD
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
|
|
Top
|
|
|
|
#111092 - 2004-01-07 06:58 PM
Re: Who belongs to this group? Using AD
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
here it can be done both ways... TranslateName() is only required if you go not have the LDAP name
Code:
break on $group = 'some_group_name' for each $member in NTDSGroupMembers($Group) ? $member next
$group = TranslateName('some_group_name') for each $member in LDAPGroupMembers($Group) ? $member next
Code:
Function NTDSGroupMembers($group, Optional $Domain) DIM $users, $obj if not $domain $domain = @domain endif if not instr($group,$domain) $group=$domain+'/'+ $group endif $obj = GetObject("WinNT://"+$group+",group") IF not $obj exit 1 endif for each $user in $obj.members $users=$users + '|' + $user.name next $obj = 0 $NTDSGroupMembers = split(substr($users,2),'|') EndFunction
function LDAPGroupMembers($Group) dim $obj,$Member,$members if not instr($group,'LDAP://') $group='LDAP://'+ $group endif $obj = getobject($Group) IF not $obj exit 1 endif for each $Member in $obj.members if $member.Class = "user" $members=$members+ '|'+$member.SamAccountName endif next $obj = 0 $LDAPGroupMembers=split(substr($members,2),'|') endfunction
Function TranslateName($LookupName, optional $LookupNameType, optional $ReturnNameType, optional $InitType, optional $BindName) Dim $NameTranslate
if not $LookupNameType and not instr($LookupName,'\') $LookupName = @domain+'\'+$LookupName endif if not $LookupNameType $LookupNameType=3 endif if not $ReturnNameType $ReturnNameType=1 endif if not $InitType $InitType=1 endif if not $BindName $BindName=@domain endif if $InitType = 3 $BindName='' endif
$NameTranslate = CREATEOBJECT("NameTranslate") if @error Exit 1 endif $NameTranslate.Init($InitType, $BindName) if @error Exit 2 endif $NameTranslate.Set($LookupNameType, $LookupName) if @error Exit 3 endif $TranslateName = $NameTranslate.Get($ReturnNameType) if @error Exit 4 endif Endfunction
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 781 anonymous users online.
|
|
|