#147584 - 2005-09-12 02:57 PM
If groupname contains...
|
talismaniak
Fresh Scripter
Registered: 2005-09-12
Posts: 12
|
I need a script that checks if a user is member of a group that contains a certain word. Let's say I need to know where a user is admin and I have groups like "New York Admin", "Dallas Admin" etc, so I want to enumerate the membership of all groups with Admin in the name.
can someone help me PLEASE!
thanx Rick
Edited by talismaniak (2005-09-12 03:00 PM)
|
Top
|
|
|
|
#147585 - 2005-09-12 03:07 PM
Re: If groupname contains...
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Code:
$localgroups = getobject('WinNT://' + @wksta) $localgroups.filter = 'group','' for each $group in $localgroups if instr($group.name,'admin') ;this local group has 'admin' in it's name ? $group.name endif next
|
Top
|
|
|
|
#147587 - 2005-09-12 09:22 PM
Re: If groupname contains...
|
talismaniak
Fresh Scripter
Registered: 2005-09-12
Posts: 12
|
Thanx for the code, I managed to enum the groups too, but this looks better.. How can I put those "admin" groups in an array so that I can use the found groups later in my script?? I allready found a enumgrouparray function on the net, but I can't get it to work... Can you help me out again??
|
Top
|
|
|
|
#147588 - 2005-09-12 10:09 PM
Re: If groupname contains...
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Code:
$localgroups = getobject('WinNT://' + @wksta) $localgroups.filter = 'group',''
DIM $admingroups[0]
for each $group in $localgroups if instr($group.name,'admin') ;this local group has 'admin' in it's name $admingroups[$i] = $group $i = $i + 1 redim preserve $admingroups[$i] EndIf next
If $i redim preserve $admingroups[$i-1] Else $admingroups=0 EndIf
for each $group in $admingroups ? $group.name next
|
Top
|
|
|
|
#147590 - 2005-09-12 11:42 PM
Re: If groupname contains...
|
talismaniak
Fresh Scripter
Registered: 2005-09-12
Posts: 12
|
Hi, thank you all.. Sorry for my bad English, but I need this for the current users membership only. I will explain why: I want to check which rights the person has and then supply him with an options menu based on that query (applicable to every query I choose). In this example "admin".
Let's say he is member of Miami Admins and New York Admins. He starts the script and the script runs a query on "admin". It returns those two groups that will appear in his menu like
"Select your options: 1. Miami Admin options 2. New York Admin options"
This script would make my life so much easier ;-))
|
Top
|
|
|
|
#147592 - 2005-09-13 12:10 AM
Re: If groupname contains...
|
talismaniak
Fresh Scripter
Registered: 2005-09-12
Posts: 12
|
Jooel, I get an error when I run your code. It says: ERROR : invalid method/function call: missing required parameter 1! on line 2...
How can I use the groups within the script to build the menu?
|
Top
|
|
|
|
#147594 - 2005-09-13 02:14 PM
Re: If groupname contains...
|
talismaniak
Fresh Scripter
Registered: 2005-09-12
Posts: 12
|
Damn I can't get it to work, I'm learning scripting by the minute, but I'm still unable to understand how i use the groupnames at a later stage in the script.
|
Top
|
|
|
|
#147596 - 2005-09-15 05:50 PM
Re: If groupname contains...
|
talismaniak
Fresh Scripter
Registered: 2005-09-12
Posts: 12
|
So I use the script Bryce wrote, I should be able to display a group witth the command "? $admingroups[1]"? This results in "IDispatch pointers not allowed in expressions!"
|
Top
|
|
|
|
#147599 - 2005-09-16 02:39 PM
Re: If groupname contains...
|
talismaniak
Fresh Scripter
Registered: 2005-09-12
Posts: 12
|
I'm running that script just to figure out how I can make use of the enumerated groups. What I want is when a user logs on, the groups containing a certain word are shown, then a user can make his selection which one he wants to start... So I thought:
for each $group in $admingroups ? $group.name Get $x ? users selection is $admingroups[$x]
and then something like: net use g: \\server\$admingroup[$x]
Must be possible somehow...
|
Top
|
|
|
|
#147601 - 2005-09-16 03:03 PM
Re: If groupname contains...
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Here's one way to do it, this presents groups with the letter "o" in them: Code:
Break ON $=SetOption("Explicit","ON") $=SetOption("WrapAtEOL","ON") Dim $iIndex, $sGroup, $sAllGroups $iIndex=0 $sGroup=EnumGroup($iIndex) While Not @ERROR AND $sGroup $iIndex=$iIndex+1 If InStr($sGroup,"o") $sAllGroups=$sAllGroups+@CRLF+$sGroup EndIf $sGroup=EnumGroup($iIndex) Loop $sAllGroups=Split($sAllGroups,@CRLF) For $iIndex=1 to UBound($sAllGroups) CStr($iIndex)+". "+$sAllGroups[$iIndex]+@CRLF Next "Enter a number between 1 and "+($iIndex-1)+" : " GetS $iIndex $iIndex=Val($iIndex) If $iIndex>0 AND $iIndex<UBound($sAllGroups) "You selected group '"+$sAllGroups[$iIndex]+@CRLF Else "You made an invalid selection"+@CRLF EndIf
|
Top
|
|
|
|
#147603 - 2005-09-16 04:14 PM
Re: If groupname contains...
|
talismaniak
Fresh Scripter
Registered: 2005-09-12
Posts: 12
|
Brilliant!! thanks... Now I can think of the next step.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 980 anonymous users online.
|
|
|