Page 1 of 1 1
Topic Options
#187267 - 2008-04-24 04:46 PM IsMember function use
alex_ Offline
Just in Town

Registered: 2008-04-24
Posts: 3
Loc: Paris, France
Hello,
I'm new in kix scripting.

I have a question about the "MemberOf" function created by ebiard http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=127566&site_id=1#import
i want to check if a user is member or not of a AD Group.
users and groups are in a file (user;group)

when i launch my script in debug mode, i have the following error message :
 Code:
ERROR : Error in expression: this type of array not supported in expressions.!
->line : $line=split($line,";")

and ismember function returns always 0 (not member) even if the user is member of the group.

I use KiXtart 2010 4.60.

Thanks if you can help me.

this is my script :
 Code:
break on
;setconsole('hide')

$fh = FreeFileHandle()
$file = "list.txt"
$result=""

if not open ($fh, $file)
   $line = ReadLine($fh)
   while not @error
	$line=split($line,";")	

	if open(3, "result.log", 5)=0
	   $user = $line[0]
	   $oldGroup = $line[1]

	   if MemberOf($oldgroup,$user)=1
		$result="isMember"
	   else
		$result = "NotMember"
	   endif

	  $x = WriteLine(3, $user+";"+$oldGroup+";"+$result+@CRLF)
	else
	? "Error result.log"
   endif

   close(3)
loop

else
   "Error list.txt"+@CRLF
endif
  


;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;FONCTIONS (DO NOT MODIFY)	
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


Function MemberOf($Groupe, OPTIONAL $User)

If ($User = "")
   $User = @USERID
EndIf

$LDAPGroupe = ""
$oLDAPGroupe = CreateObject("NameTranslate")
If Not(@ERROR)
    $oLDAPGroupe.Init(3, "")
    If Not(@ERROR)
        $oLDAPGroupe.Set(3,"@DOMAIN\"+$Groupe)
        If Not(@ERROR)
           $LDAPGroupe = $oLDAPGroupe.Get(1)
        EndIf
    EndIf
EndIf

$oGroupe = GetObject("LDAP://" + $LDAPGroupe)

If Not(@ERROR)
    For Each $Objet In $oGroupe.Members
	Select
	Case $Objet.Class = "group"
	   $Result = MemberOf($Objet.cn, $User)
	   If ($Result = 1)
		$MemberOf= 1
		Return
	   EndIf

    	Case $Objet.Class = "user"
	   If ($Objet.samAccountName == @USERID)
		$MemberOf= 1
		Return
	   EndIf
	EndSelect
    Next
EndIf

$MemberOf = 0
EndFunction 



Edited by alex_ (2008-04-25 04:04 PM)

Top
#187281 - 2008-04-24 10:25 PM Re: IsMember function use [Re: alex_]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You could use the build in InGroup() function to see if a user is a member of an AD group.

If you want to see membership of a GroupB when the user is a member of GroupA and GroupA is a member of GroupB the there is a UDF called ListeNestedGroups (not sure about the exact name) that can show you membership of a group and membership if nested groups.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187292 - 2008-04-25 09:40 AM Re: IsMember function use [Re: Mart]
alex_ Offline
Just in Town

Registered: 2008-04-24
Posts: 3
Loc: Paris, France
maybe i'm wrong, but i think ingroup() fonction is used to see if the current user is member or not.

In my case, i want to see if the users who are in my text file are (or not) members of group1 and group2 (text file : user;group1;group2)


My script is not launch with the loginscript.

Top
#187299 - 2008-04-25 12:19 PM Re: IsMember function use [Re: alex_]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Below is an example that should work.

This script requires the UserGroups() UDF.
UDF Library » UserGroups() - returns all groups of a given user

 Code:
Break on

$rc = Open (1, "c:\usernames.txt", 2)

$line = ReadLine(1)

While Not @ERROR And Trim($line) <> ""
	$line = Split($line, ";")
	$usergroups = UserGroups(@DOMAIN, $line[0])
	If UBound($usergroups) <> -1
		For Each $usergroup in $usergroups
			If $usergroup = $line[1] Or  $usergroup = $line[2]
				?$line[0] " is a meber of " $line[1] " or " $line[2]
			Else
				?$line[0] " is not a meber of " $line[1] " or " $line[2]
		Next
	Else
		? $line " does not have any groupmemberships. "
	EndIf
	Sleep 2
	$line = ReadLine(1)
Loop

$rc = Close (1)


Edited by Mart (2008-04-25 12:20 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187308 - 2008-04-25 04:03 PM Re: IsMember function use [Re: Mart]
alex_ Offline
Just in Town

Registered: 2008-04-24
Posts: 3
Loc: Paris, France
ok. thanks. i'll try that.
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 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.049 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org