[THIN] Re: OT: VBS Script - Help

  • From: "Robert Barrett" <RobertB@xxxxxxxxxx>
  • To: <thin@xxxxxxxxxxxxx>
  • Date: Wed, 29 Sep 2004 08:26:07 -0600

That helped, thanks.  I forgot to mention I am rather new to the
scripting field. Most of that I pulled off the net and modified.
Anyway, the other thing that I had to do to get it to work was set the
group name that I was using for comparison to CN=Student Internet.  FOr
some reason, and maybe this is normal, when you enumerate the groups and
check the member.name is pulls out not just the name but the CN= part as
well.  Hence, it would never evaluate to what I wanted.  Oh well, live
and learn.  Thanks
 
Bob Barrett
FVSD#52
 

________________________________

From: thin-bounce@xxxxxxxxxxxxx [mailto:thin-bounce@xxxxxxxxxxxxx] On
Behalf Of Shonk, Joe - Perot
Sent: Tuesday, September 28, 2004 5:06 PM
To: thin@xxxxxxxxxxxxx
Subject: [THIN] Re: OT: VBS Script - Help



Try rewriting your logic

 

grpmember = 0

For Each Member in ObjUser.Groups
  If member.name = "Student Internet" THEN
     grpmember = 1
  End If
Next

 

 Also change:

 

 If grpmember = 1  THEN
  wscript.echo User & " is already a member of Student Internet group"
 ELSE
  grp.Add(objUser.AdsPath)
  grp.SetInfo
  wscript.echo User & " has been added to the Student Internet group"
 End If
Next 

 

 

 

________________________________

From: Robert Barrett [mailto:RobertB@xxxxxxxxxx] 
Sent: Tuesday, September 28, 2004 3:32 PM
To: thin@xxxxxxxxxxxxx
Subject: [THIN] OT: VBS Script - Help

 

Hi all,

 

I work at a K-12 school division and we are trying to get our school
based people to look after their own students.  They are only
responsible for resetting passwords, unlocking accounts and adding
students to the Internet group when they have the appropriate permission
slips signed.  We have created a taskpad for them to use and everything
works wonderful except the adding to groups.  I cobbled together a vbs
script that runs after they click on a name and press the button, that
is all good. It will add the user to a group if they are not a member,
but what I cannot get it to do is to check membership and tell the
teacher that the student is already a member of that group.  It always
tries to add the user and of course throws an error.  I don't want them
to have to deal with script errors.  So this is the script, where am I
going wrong. The grpmember echoes are just to check the values as I went
through.  It always evaluates to 0, I realize I have to break out of the
loop when it evaluates to 1 to prevent the overwrite but it never does.

 

Const EVENT_SUCCESS = 0

 

Dim grpmember

 

'This code checks to see whether a user is selected and prevents use of
this script without the snap-in.
If WScript.Arguments.Count = 0 Then 
 WScript.Echo "No User Selected" 
 WScript.Quit 
End If 

 

'This code converts the username to an LDAP string. 
For Each User In WScript.Arguments 
 objFirstPart = "LDAP://cn="; 

 

 'Edit the next line to match your OU and domain structure. 
 objLastPart = ",OU=School,OU=student ,DC=fvsd,DC=ab,DC=ca" 
 objLDAPNAME = objFirstPart & User & ObjLastPart 
 set objUser = GetObject (ObjLDAPNAME) 
 set grp = GetObject ("LDAP://CN=Student Internet, OU=School,
OU=Student, DC=fvsd, DC=ab, DC=ca")

 

 For Each Member in ObjUser.Groups
  If member.name <> "Student Internet" THEN
   grpmember = 0
   wscript.echo grpmember & " false"
  ELSE
   grpmember = 1
   wscript.echo grpmember & " true"
  End If
 Next

 

 wscript.echo grpmember

 

 If grpmember <> 0 THEN
  wscript.echo User & " is already a member of Student Internet group"
 ELSE
  grp.Add(objUser.AdsPath)
  grp.SetInfo
  wscript.echo User & " has been added to the Student Internet group"
 End If
Next 

 

 

 


Robert Barrett MCSE, CCA

Enterprise Administrator

robertb@xxxxxxxxxx <mailto:robertb@xxxxxxxxxx> 
Phone: (780) 927-3766

Fax: (780) 926-3037

http://www.fvsd.ab.ca <http://www.fvsd.ab.ca/> 

 

 

GIF image

Other related posts: