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******

 Code:
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!!!