FN-GM Posted March 18, 2008 Posted March 18, 2008 We have this password reset script it works fine. How do i make an alteration so that it will only reset password an OU called "students" please? This is our script. Dim sUserName, sDomain, oUser, oNet, sComputer, pw, vbClrf, _ sPword2, sPword3, oComputer sUserName = InputBox("Please type Username", "Password Change") bConfirm = MsgBox ("Password to be reset, are you sure?", 4, sUsername) If bConfirm = 7 then wscript.Quit Set oNet = CreateObject("Wscript.Network") sDomain = "HCHS" sPword = "football" sComputer = oNet.ComputerName Set oUser = GetObject("WinNT://" & sDomain & "/" & sUserName & _ ",user") oUser.SetPassword sPword oUser.Put "PasswordExpired", 1 oUser.SetInfo WScript.Echo "The password for user account " & chr(13) & chr(13) & sUserName & chr(13) & chr(13) & " in domain " & sDomain & " has been reset to football." 'Additional script to log the changing of passwords 'Dim filesys, testfile 'Set filesys = CreateObject("Scripting.FileSystemObject") 'Set testfile= filesys.CreateTextFile("passwords.txt", True) 'testfile.WriteLine sUsername 'testfile.Close dim filesys, filetxt Const ForReading = 1, ForWriting = 2, ForAppending = 8 Set filesys = CreateObject("Scripting.FileSystemObject") Set filetxt = filesys.OpenTextFile("passwords.txt", ForAppending, True) filetxt.WriteLine sUsername & " , Password reset , " & date & " , " & Time filetxt.Close Would i put something like this in? if NOT userou = "Students" then call notstudentaccount But where would i put that? Thanks alot
cl0n3 Posted March 18, 2008 Posted March 18, 2008 What is it that you want to happen if the user is not from the student group? Sorry, can't really say where to put it without knowing what action you would like taken.
FN-GM Posted March 18, 2008 Author Posted March 18, 2008 Hi I just want the script to reset passwords on accounts that come under an ou call students. Basically i don't want it able to reset staff and service account passwords.
cl0n3 Posted March 18, 2008 Posted March 18, 2008 So the script will bulk change all student users to the same password or are you sticking with current method of typing in each user you want to change?
FN-GM Posted March 18, 2008 Author Posted March 18, 2008 This is for teachers use. They will type the student’s username in and it will reset the password. I want to make it so it will only reset student passwords.
ChrisH Posted March 18, 2008 Posted March 18, 2008 You need to change this line: Set oUser = GetObject("WinNT://" & sDomain & "/" & sUserName & _ ",user") To use an ldap path method like: Set oUser = GetObject("LDAP://cn=" & sUserName & ",ou=students,dc=MyDomain,dc=com") Thats no 100% accurate but you get the idea. You will also need some error trapping incase its not found etc.
FN-GM Posted March 18, 2008 Author Posted March 18, 2008 What if they are in an ou that lives under students? Will it still work please? Thanks
ChrisH Posted March 18, 2008 Posted March 18, 2008 you need to work out the full LDAP path you work backwards eg if the ou was students > Year 7 the path would be cn=joe bloggs,ou=year7,ou=students,dc=MyDomain,dc=com
FN-GM Posted March 19, 2008 Author Posted March 19, 2008 ok, is it possible so it will only reset passwords for users in a particular group? Thanks Z
FN-GM Posted March 20, 2008 Author Posted March 20, 2008 Just going to give this a bump is it possible to configure it so it will only reset passwords for users in a particular group please? Thanks
webman Posted March 20, 2008 Posted March 20, 2008 http://www.sanx.org/tipShow.asp?index=66 Found using Google.
FN-GM Posted March 20, 2008 Author Posted March 20, 2008 ok so i have this Private Function IsMember(groupName) Set netObj = CreateObject("WScript.Network") domain = netObj.UserDomain user = netObj.UserName flgIsMember = false Set userObj = GetObject("WinNT://" & domain & "/" & user & ",user") For Each grp In userObj.Groups If grp.Name = groupName Then flgIsMember = true Exit For End If Next IsMember = flgIsMember Set userObj = nothing Set netObj = nothing End Function how do i get that to work how i want it to please?
Edu-IT Posted March 20, 2008 Posted March 20, 2008 I would suggest first reading through the code and trying to identify what each part does. Then look at your script and work out what each part does. Then try and combine the code to get what you need. The code you posted checks that a user is part of a group and then returns either a true or false value. So if true you want the password to be changed and if false you perhaps want to display some sort of error message.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now