Oh and any comments or suggestions are welcomed.
Ok I have been promising to produce something like this so after the morning gardening this has been my therapy :P
This is a GUI front end for a script I produced in VB script last year.
The full features of the original script included:
Import information from a CSV file.
Creation of home directories and setting of permission and ownership (Using cacls and the windows version of CHOWN)
**** The author takes no responsibility for any damage that could be caused by this script USE AT YOUR OWN RISK!!!!!!!!! ****
Current version 1.0
This must be run on a Windows XP machine that is a member of a domain
At the moment it will read the following information from a CSV file (in this order)
Surname, First Name, UserName, Password
It is also assumed that the OU already exists and you must specify a group
that must be in the same OU as the users are going. This will be made more flexible later
As I gradually migrate the code over I will be adding the following features:
Add more fields to be inputed through the GUI such as:
home drive path, home drive letter
Other functions to include the creation of home directory and setting ownership and permissions.
Smarten up the HTML so it doesnt look like a year 7 produced it :P
Ok its looking quiete good now. The error checking is mostly in and seems to work ok. Check out the avi on the second page. I have also added a visual log.
I will post the current version once I have got rid of a few bugs
Oh and any comments or suggestions are welcomed.
Thtas fantastic, Thanks Chris, I'm sure some people will prettify and expand it quite rapidly!!
I have most of the code already to slot in. It will just need a little rearranging. The only thing I would have to write from scratch would be the username generation routine as mine is hard coded to our naming scheme but that shouldnt be too hard.
Wowser! Thanks Chris - will test it out and give some feedback soon.
Good good. The test button on the OU field isnt implemented yet btw.
Nice one i can make changes to mine so its hta too or make changes to yours. Thanks for this.
I made a single-user vbscript which did this sort of thing all-in-one so that I didn't have to mess around when a new pupil came to the school in the middle of a school year. It's quite handy for quickly creating test accounts too.
On top of the basics, it made the home folder, set permissions on it and created a share on it (as well as setting all the properties of their account I needed e.g. group memberships*). I did some bits of it by calling cacls.exe and rmtshare.exe with WshShell.Run rather than pure VB, because I didn't have any great plans on distributing it to anyone else.
The only thing I never got round to was creating their mailbox in Exchange, because that needed more advanced veebee voodoo. If I look at it again, I'll probably use this:
because laziness generally wins against elegance!
If you want the code, PM me - it's so heavily customised for our particular setup that it wouldn't be much use as a starting point for people, but you might be able to lift bits you like.
One feature request would be to let the csv file have column headers, so that you could make some parameters optional. It's worth bearing in mind though that a lot of properties of user accounts can be done in bulk in WS2003's ADUC by multi-selecting so there's not much of a time-saving aspect after you consider that you have to generate the csv file in the first place.
*yes, I know that isn't technically a property of the user account!
My original script that is fully working is much the same as yours. I used cacls for permissions and the the windows version of CHOWN for ownership.
I didnt even think about Exchange thought so I will put that on list.
That is a good suggestion about the column headers for the CSV file I do have them currently on the version I am using but they are more of a guide when you first start putting data into it. I will make it more intelligent though as you suggested.
The thing im struggling on at the moment is the error trapping. To check the existence of a user an object in AD I use something like this:
This works fine in a VB script but put the when ran this way it doesnt like it and it comes up with a Internet Explorer error. Using "On Error Resume Next" doesnt work in this context either.Code:Set ObjParent = Getobject (OUPath) 'Get the container MsgBox Err.Number If Err.Number <> 0 Then CheckOUExists = False Msgbox "The OU was not found try again" Else CheckOUExists = True MsgBox "OU Exists" Err.Clear End If 'Error handling
Can someone enlighten me as to what kind of construct I need to use.
I have found a temporary answer by suppressing the error with some JScript:
Ok its looking like error checking needs to be done is JS I think?
Does anyone have any input on this?
(and I thought this was going to be a simple transition )
I haven't tested that, so caveat scriptor, but I guess you could use the stuff on that page to pull some information out about the error and process it.Handling window.onerror in VBScript
As you can see, the VBScript syntax for installing an event handler requires naming a function in the convention object_event. In this case we want to install a handler for the onerror event on the window object, so we create a VBScript function named window_onerror. Also, in VBScript, return values are indicated by assignment to a variable named after the function.Code:<SCRIPT language="VBScript"> Function window_onerror ( message, url, line ) window_onerror = true End Function </SCRIPT>
Thanks I had got halfway there by having it generate a generic error but just needed to pass "message" to the function so it came up with the proper error which it seems to be doing quite well.
Oh well least I learned something new today
Ok I have made a slight update. I have updated the code and the download above.
I have added fields for a group to add the users to and given the option to disable users on creation.
You can also now choose an OU at any depth as long as you specify the path.
If you have a top level OU called students and a year7 OU in there then you must type in
No space either side of the comma. So basically your working your way backwards to the top level. If you press test it will check of the OU exists and display the LDAP path to you.Code:year7,students
I'm still working on the error correction as it seems I have to use java script for this which I wasnt expecting (if anyone knows better let me know)
This can break in several parts including:
The OU doesnt exist or you types the path wrong.
The group field is left blank (You must put something at the moment).
The group object is not in the same place as the users are going to (will make that more flexible later).
The user objects already exist.
The code might be a bit sloppy in places but I will tidy up once everything is working.
Right well after seeing the code for another HTA which was using normal VBS error control I thought wtf!!! I then realised shortly before kicking myself very hard that the reason the error checking was not working was because all of my VB code was in Functions and Subs so my On error resume next statement that I had just plonked above them all had no effect ops:
So this is much better for me and will spend some time on it tommorow and release something a little prettier with more functionality and more inportant a little more stable
Ok this is going along nicely at the moment. All the error checking code is working nicely and I have a visual log that runs as the script executes. I havent updated the first post as I still have a few more bugs to iron out.
I am attaching a html file with a mock up of the interface. If anyone wants to mess around with the styles and make it look a bit better then please be my guest (so I can concentrate on the coding ) . Just makes sure it fits within the current width dimensions of the left and right content divs.
Once I get this running to my satisfaction I will work on the next phase which will be more intelligent routines from reading from the CSV file. This will involve a first screen where you select the file and it reads the column headers. It will then on the second screen add the common fields that arent accounted for in the CSV file.
This will allow more flexibility to allow different values for fields like description read in from the file or the same for all if input from the GUI.
PS I just noticed its broken under firefox as it's been running under a HTA in an explorer process I didnt notice :P
There are currently 1 users browsing this thread. (0 members and 1 guests)