Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through collection

Status
Not open for further replies.

ErrolDC

MIS
May 26, 2004
72
US
Hi all-

I am new to vbscripting and I'm trying to determine the best way to accomplish a task.

I'm writing a script that is run when a user logs on to our domain. If the user is a member of the Executives group, I need the script to terminate. Here is what I have so far:

set objNet = CreateObject("Wscript.NetWork")
dim username
dim domainname
username = objNet.UserName
domainname = objNet.UserDomain
Set User = GetObject("WinNT://" & domainname & "/" & username & ",user")
For Each Group in User.Groups

This is where I'm stuck. What I want to do is loop through all the groups the user is a member of. When we are done processing, if the user belongs to the group, exit the script immediately. If the user does not belong to that group, then continue processing. Any one got suggestions?
 
Okay, I managed to solve this issue. I set a variable named count and as I looped through the group names, I incremented the value if I found at match. If the value of count is greater than it's initial value, then I know they are members of the Group I do not want to process..

Okay, here is my next question, I have more than one group however. How can I access an array with more than one value via a statement like:

If Group.Name = Array then..
I've seen stuff like "For each value in Array", but I want to process this in one line..

 
You can't really process an array in one line. The whole point of arrays is to treat each piece of data as an individual element. You could conceivably Join the array then use something like InStr to determine if the string you were interested in is in the array, but this is a really bad idea IMO.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top