#196588 - 2009-11-05 05:07 PM
Enumerate Group Membership using wild card
|
synwave7
Fresh Scripter
Registered: 2002-01-27
Posts: 49
Loc: Chicago, IL. 60601
|
Can someone help me with this script. I suck at scripting so I snag everyone elses scripts and build them to suit me. I just haven't scripted in EONS so what would take me a week I can imagine would take one of the veterans two seconds to correct.
My question/need. Can someone edit this script to do...
I need to know (enumerate) all groups in my AD that start with (whatever) in this case APP-Citrix. Can I use a wild card in the script? In other words I want to create output that will output to a .txt or excel doc the membership of any group I choose.
In the pasted peice of script below...Can I use that * as a wild card so the script Lists the Group Name and who is in it I need or want to pipe the output to an Excel doc or at the least a .txt doc or .csv doc.
$members = groupmembers(@LDOMAIN, "APP-Citrix*")
SCRIPT I CUT AND PASTED FROM THIS SITE************STARTS BELOW******
Break on
$members = groupmembers(@LDOMAIN, "Group1")
For Each $member in $members
? $member
Next
Sleep 5
;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")
Function Groupmembers($target, $group, optional $flag)
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
Edited by synwave7 (2009-11-05 05:13 PM) Edit Reason: didnt follow post code rules
_________________________
Bang that head that doesn't bang!!!
|
Top
|
|
|
|
#196590 - 2009-11-05 07:29 PM
Re: Enumerate Group Membership using wild card
[Re: synwave7]
|
synwave7
Fresh Scripter
Registered: 2002-01-27
Posts: 49
Loc: Chicago, IL. 60601
|
So I did some testing of my own after following the directions on the site here. I added the Debug on script piece and I get the following error from my script.
ERROR : undefined variable [members]! Script: h:\groupmembership.kix Line : 9
Here's the whole code...can someone help I tried time and again but can't get this script to work...
Break on
Debug on
DIM $rc
$rc=SETOPTION('explicit','on')
$rc=SETOPTION('novarsinstrings','on')
$members = groupmembers("mydomainname","activesync")
For Each $member in $members
? $member
Next
Sleep 5
;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 member of.
;
; "Kixtart/beanbag" will produce information on 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 will return all members of the Domain Admins group in the kixtart domain.
; $members = groupmembers("kixtart","Domain admins")
;
; ;this will return all groups in the local administrators group on
; ;the Workstation beanbag in the kixtart domain. Also the
; $groups = groupmembers("kixtart/beanbag","Administrators","group")
Function Groupmembers($target, $group, optional $flag)
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
Edited by synwave7 (2009-11-05 07:30 PM) Edit Reason: did not want to show my domain name so I took it out and gave bogus name
_________________________
Bang that head that doesn't bang!!!
|
Top
|
|
|
|
#196591 - 2009-11-05 09:05 PM
Re: Enumerate Group Membership using wild card
[Re: synwave7]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
Replace
with
DIM $rc, $member, $members
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|