[THIN] Re: OT: VBS Script - Help

  • From: Jeff Malczewski <jmalczewski@xxxxxxxx>
  • To: "'thin@xxxxxxxxxxxxx'" <thin@xxxxxxxxxxxxx>
  • Date: Wed, 29 Sep 2004 09:05:28 -0400

Or you could just use the ismember method..
 
member=false
set grp = GetObject("CN=<groupname>,OU=xxxx,DC=xxxx,DC=xxxx")
member = grp.IsMember("CN=<username>,OU=xxxx,DC=xxxx,DC=xxxx")
If (member=true) Then 
    wscript.echo("Already member")
else
    blah blah
end if
 

-----Original Message-----
From: Shonk, Joe - Perot [mailto:JShonk@xxxxxxx]
Sent: Tuesday, September 28, 2004 7: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 <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 <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

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

Fax: (780) 926-3037

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



 


----------------------------------
This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. If 
you have received this email in error please notify the system manager. This 
message contains confidential information and is intended only for the 
individual named. If you are not the named addressee you should not 
disseminate, distribute or copy this e-mail.

Attachment: image001.gif
Description: GIF image

Other related posts: