Re: Cycle through variables
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 9 Jun 2006 11:05:17 -0500
Tim Chin wrote:
Is there a way to specify a list of say 20 variables in a script and runHi,
the same command for all variables without copying pasting the command 20
times in a script? Below is an example of my current script - I'd really
like to simplify it to make future modifications much easier. It looks
like there are two options that may produce my desired end result - using
an array and/or using multiple instances of the same variable, for
example: Group(1) = group in domain1, Group(2) = group in domain2, etc.
Can anyone shed some light on how to cycle through many variables to the
same command?
Group01="cn=somegroup,ou=somou,dc=domain1,dc=com"
Group02="cn=somegroup,ou=somou,dc=domain2,dc=com"
(etc.)
Set objGroup = GetObject ("LDAP://"&Group01)
For each objMember in objGroup.Members
i = i + 1
AlertReportXX = i&". "&objMember.sAMAccountName&" (domain.com)"
objTextFile2.WriteLine(AlertReportXX)
EchoXX = "domain.com,,"&objMember.sAMAccountName
objTextFile.WriteLine(EchoXX)
Next
Set objGroup = GetObject ("LDAP://"&Group02)
For each objMember in objGroup.Members
i = i + 1
AlertReportXX = i&". "&objMember.sAMAccountName&" (domain.com)"
objTextFile2.WriteLine(AlertReportXX)
EchoXX = "domain.com,,"&objMember.sAMAccountName
objTextFile.WriteLine(EchoXX)
Next
(etc.)
wscript.echo i
wscript.quit
You can use a subroutine. Call the subroutine once for each group
distinguished name. Define objTextFile and objTextFile2 outside of the Sub
so they have global scope. Since i is probably meant to be a cumulative
total, also give it global scope by declaring it outside the Sub.
========================
' Declare variables with global scope.
Dim objTextFile, objTextFile2, i
Set objTextFile = ...
Set objTextFile2 = ...
i = 0
Call EnumGroup("cn=somegroup,ou=somou,dc=domain1,dc=com")
Call EnumGroup("cn=somegroup,ou=somou,dc=domain2,dc=com")
'(etc.)
Wscript.Echo i
Wscript.Quit
Sub EnumGroup(strGroup)
Set objGroup = GetObject ("LDAP://" & strGroup)
For each objMember in objGroup.Members
i = i + 1
AlertReportXX = i&". "&objMember.sAMAccountName&" (domain.com)"
objTextFile2.WriteLine(AlertReportXX)
EchoXX = "domain.com,,"&objMember.sAMAccountName
objTextFile.WriteLine(EchoXX)
Next
End Sub
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
.
- Follow-Ups:
- Re: Cycle through variables
- From: Tim Chin
- Re: Cycle through variables
- References:
- Cycle through variables
- From: Tim Chin
- Cycle through variables
- Prev by Date: Download a website's source with VBS
- Next by Date: Re: How can I follow a trail of 302 redirects with MSXML2.XMLHTTP?
- Previous by thread: Cycle through variables
- Next by thread: Re: Cycle through variables
- Index(es):
Relevant Pages
|