#19391 - 2002-04-04 10:49 AM
Re: I have a Challenge.
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
Mr. Mustang.... Bryce (your fellow TEXAN [remember the Alamo] has done all the hard work for you - and quite a good job at that. Good Job Bryce
Simply copy the code from the CODE section and paste into WORD, then copy again inside WORD and paste it into NOTEPAD or your favorite Text Editor and run the code. It will not do anything except show you what it will do.
You need to supply a list of allowed users beyond what the @userid supplies otherwise it will remove everyone except the currently logged in user.
code:
BREAK ON $allowed_admins = "administrator, @userid"
;get a listing of all members of the local administraotr group $localadminusers = groupmembers("@domain/@wksta","Administrators",18)
;get a connection to the localadmin group $localadmingroup = getobject("WinNT://@domain/@wksta/administrators,group")
for each $admin in $localadminusers if instr($allowed_admins,$admin.name) = 0 ;a user has been found that is not in the $allowed_users list, ;and will now be removed.
? "Removing " + $admin.name + " from " + $localadmingroup.name ;to make this code work, you will have to uncomment the following line. ;$localadmingroup.remove($admin.adspath) endif next
Function Groupmembers($target, $group, optional $flag) ;NAME GroupMembers ; ;ACTION Returns an array of all group members of the specified group ; ;SYNTAX GroupMembers(Target, Group, [FLAG]) ; ;PARAMETERS Target ; The Domain name or Workstation to work with. For faster workstation ; execution, include the Domain Name that the workstation is a meber of. ; ; "Kixtart/beanbag" would be working with the workstation Beanbag in the ; Kixtart domain ; ; Group ; The Group you want to query ; ; [FLAGS] ; To use the flags options add the numbers of the desired flags toghthers and ; Use that number in the flag field. ; ; Filter :(only one filter flag at a time please) ; 1 = all ; 2 = Users only ; 4 = Groups only ; ; ADSI Information(return ADSI information "pick only one") ; 8 = ADSPath field ; 16 = ADSI Object Handle ; ;RETURNS an array containing , if the ADSPath option is used the ADSPath ; will also be returned |. ; ;REMARKS ADSI com object must be installed. ; ;EXAMPLES ;this return all members of the Domain Admins group in the kixtart domain. ; $members = groupmembers("kixtart","Domain admins") ; ; ;this will will return all groups in the local administrators group on ; ;the Workstation beanbad in the kixtart domain. Also the ; $groups = groupmembers("kixtart/beanbag","Administratoos","group") DIM $temparray[8], $member, $i, $chunk, $flag, $ADSIFlag, $filterFlag $chunk = ubound($temparray) $flag = val($flag) $i = 0 $group = getobject("WinNT://$target/$group") if vartype($group) <> 9 exit(@error) endif select case $flag & 1 $filterflag = 1 case $flag & 2 $filterflag = 2 case $flag & 4 $filterflag = 4 case 1 $filterflag = 1 endselect select case $flag & 8 $ADSIFlag = 8 case $flag & 16 $ADSIFlag = 16 endselect for each $member in $group.members select case $filterflag = 2 AND $member.class = "user" if substr($member.name,len($member.name),1) <> "$" $temparray[$i] = $member.name select case $adsiflag = 8 $temparray[$i] = $member.adspath case $adsiflag = 16 $temparray[$i] = $member endselect $i = $i + 1 endif case $filterflag = 4 AND $member.class = "Group" if substr($member.name,len($member.name),1) <> "$" $temparray[$i] = $member.name select case $adsiflag = 8 $temparray[$i] = $member.adspath case $adsiflag = 16 $temparray[$i] = $member endselect $i = $i + 1 endif case $filterflag = 1 if substr($member.name,len($member.name),1) <> "$" $temparray[$i] = $member.name select case $adsiflag = 8 $temparray[$i] = $member.adspath case $adsiflag = 16 $temparray[$i] = $member endselect $i = $i + 1 endif case $filterflag ;bit bucket endselect if $i = ubound($temparray) redim preserve $temparray[Ubound($temparray)+$chunk] endif next if $i <> 0 redim preserve $temparray[$i-1] $groupmembers=$temparray endif endfunction
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 764 anonymous users online.
|
|
|