#162199 - 2006-05-21 06:05 AM
Mass user creation script for a high school
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
Hi everyone,
I'm a computer technician in a high school (anymore of you out there?)
One of our downtown techs created a vbs script to mass create user accounts at each school under our district's 2003 AD structure. He had to make it fairly general to accomodate the needs of each school. So, I'd like to tweak it and I thought that using kix would be the easiest.
From reviewing this site and others, I think I can figure out how to create one account with all it's properties and home folder etc. But I need some help with what terms I should search for to find help with the following concepts:
1. How to extract student information data from the SIRS database (sql) and turn it into a csv file. (If that's a lot of trouble, it is fairly simple just to open the SIRS program and export the data to a csv file).
2. I need to know how to create a loop that will take one line at a time from the csv file and use it to create the user accounts etc.
3. I also need to know if it's more logical to have one loop that does everything at once or should I have three loops; one to create accounts, one to creat home directories and one to create the log file.
4. Finally, I'd like to know if this script seems possible. Or have I bitten off a bit more then I might want to chew.
Thanks in advance for all suggestions,
Jeremy
Code:
; =========================================================================================== ; ; Script Information ; ; Title: Bishop Grandin High School Mass Users Create Program ; Author: Jeremy Schubert ; Description: This script is to be used to create the student computer accounts each semester. ; ; ===========================================================================================
;This script must be Run from the school's computer technician's computer as that machine has ;access to both the \\adminserver And the \\studentserver. ; ;This program has four parts. ; ;1. It will grab the following information from the SIRS from \\adminserver\sirs3$ ; (Student Information Records Database, http://www.migsirs.com/cgi-bin/load.pl?page=products): ; Legal First Name, Legal Last Name, Alberta Student ID #, Home Telephone Number, Grade ; It will put that data into a csv file named sirsimport.csv. ; It will then massage the data in the file as follows: ; Remove the area code ; Remove any of the following characters: coma,bracket,hyphen,white-space ; Will change any 'unlisted' phone number to 5555555 ; Will combine the first And last legal names into one column in the format of fistname.lastname (which will then become the user account name) ; Will truncate any user account name longer then twenty characters. ; ;2. It will create a home drive For Each user ; The following attributes will be applied While creating the home folders: ; The folders will be named firstname.lastname ; The share name will be firstname.lastname$ ; The folders user limit will be Set to 5 ; The folder will be housed in \\studentserver\users$\students\grade10,grade11, Or 12 ; The share permissions will be Set as follows: ; Domain Administrators will have full control ; User And the teacher group will have change control ; The security permissions will be Set as follows: ; Administrators, Domain Administrators, And System will have full control ; User And the teacher group will have modify ; ;3. It will create a user account For Each user. ; The user accounts will all be put in to the following OU ; domain\user accounts\section06\school047\047Ustudents ; The user accounts will all be added to the following two Global groups: ; ggsection06-students And ggschool047-students ; The user accounts will Each be added to one of the following Global groups: ; gg047-grade10,gg047-grade11,gg047-grade12 ; The following properties will be entered For Each user account ; Legal first name And legal last name ; Account name as firstname.lastname ; Password will be their seven digit telephone number And Password will be Set to change on Next logoin ; Home drive path will be \\studentserver\firstname.lastname$ ; Profile path will ber \\studentserver\student.man$ ; The student's grade and Alberta Education identification number will be entered into ; one of the propertie's fields. ; The accout will be enabled. ; ;4. It will breat a log file ; The log file will be saved to \\studentserver\c$\logs\massu.log ; The log file will record the following events For Each account created: ; "An account has been created for firstname lastname" ; "The account's initial password is xxxxxxx and they will be required to change their password at first login" ; "The user's home folder is located at \\studentserver\users$\students\gradexx" ; "The user has been placed in the ggsection06-students and the ggschool047-students global groups" ; "The user has been placed in the gg047-gradexx global group" ; "The account has been enabled" ; ;The script will end with the message ;"The script is complete. X number of user accounts have been created." ;
;Part One - Grab the information information from SIRS Database (SQL)
;Part Two - Create a loop to create the Home folder for each student
;Part Three - Create a loop to create the User Account for each student
;Part Four - Creat a loop to report success to the log file
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#162201 - 2006-05-21 04:30 PM
Re: Mass user creation script for a high school
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
To get to the SQL DB, you can use ODBCSQL().. I think there are some other SQL-Related UDFs for creating recordsets, etc.
Kent
|
|
Top
|
|
|
|
#162203 - 2006-05-21 10:20 PM
Re: Mass user creation script for a high school
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
Thanks for all the suggestions thus far. I have decided that for now I'm going to concentrate on all parts of the script except for the extracting of info from the sql database. That can come later as I can easily export the data from within the program now.
But I've also learnt that I'm going to have to have a check in the loop to make sure the samaccount name is unique accross the domain. Then I'll have to decide if it's easier just to have the error reported to the log to deal with or if I can make the script attempt to revise the samaccount name.
Another interesting thing I found out is that though the samaccount needs to be usique, the distinguished name can be repeated. Go figure.
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#162205 - 2006-05-22 12:08 AM
Re: Mass user creation script for a high school
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
|
|
Top
|
|
|
|
#162207 - 2006-05-22 03:11 PM
Re: Mass user creation script for a high school
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
Thanks Howard. That link provides some excellent ideas. I don't think this should be too hard with all the examples I'm getting. Thanks.
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#162208 - 2006-05-22 03:15 PM
Re: Mass user creation script for a high school
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
Thanks Doc, what you say makes excellent sense. I still get a little nervous when I think of programming (scriptiting). Thinking I don't necessarily have the logic know how. But, like you said, I really just have to follow the format of the script created by our downtown tech. And I suppose that as I begin to examine more scripts on this board, I'll eventually begin to figure out the logic.
Jeremy
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#162210 - 2006-05-22 08:40 PM
Re: Mass user creation script for a high school
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
Practice make perfect (unless it makes pregnant :>>) I think intimadating might have been a better word then nervous.
Anyway, you're right. Why reinvent the wheel. Basically I should just be able to translate the vbs into kix and add a few steps. But, it's a holiday in Canada today (Queen's birthday). So I'm not going to worry about it til at least tomorrow.
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#162212 - 2006-05-22 10:12 PM
Re: Mass user creation script for a high school
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
The beautiful ciy of Calgary, Alberta.
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#162213 - 2006-05-23 04:49 PM
Re: Mass user creation script for a high school
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
Turns out the database is based on FoxPro, not sql. Are there UDFs for FoxPro?
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
#162214 - 2006-05-23 04:57 PM
Re: Mass user creation script for a high school
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You should be able to use the same code with the appropriate ODBC driver.
|
|
Top
|
|
|
|
#162216 - 2006-05-29 04:50 AM
Re: Mass user creation script for a high school - draft one
|
jeremyschubert
Getting the hang of it
Registered: 2005-09-17
Posts: 89
|
OK folks, below is the first draft of a mass user creation vbs script I'm trying to convert into Kix. Bob Kelly's book, "Scripting with Kixtart" has a short but informative section on converting VBS to Kix and that helped. But please be gentle, I'm still a newbie to Kix (and vbs for that matter!). 
So here are the things I think I still need to work on. Please feel free to add to the list.
1. There's a vbs section with what looks like variables all preceded by CONST. I have to figure out what to do there.
2. I have to figure out what to do with Create$Object.
3. I think I have to change 'err.number = 0' to 'error = 0' (without the quotes) and 'if (err.number <> 0' to something like 'if error <> 0'.
4. I think there's a few exist statements I have to convert from vbs to kix.
5.I need to sort through the whole log file section.
6. There's a fs.createfolder command that I think needs to be converted from vbs to kix.
7. Is objUser.put a valid kix command?
8. I have to figure out what to do with $objFile.write/close/etc.
9. There is a difference between some of the values that are in the original script and what I want to put in. (I.E add the profile path and change the home folders names from lastname.firstinitial to firstname.lastname).
There's probably lots of other mistakes (and sorry for the length of this post). But I'd really appreciate any help you have the time to give me.
Oh, and I've decided not to include the extraction of data from the foxpro database yet. One thing at a time!
Code:
; Used to be a VBscript (now is a KIX script) to create multiple user accounts from a text file supplied by user ; text file layout needs to be the following ; Student ID, Last Name, First Name, Grade, Phone Number ; ; 1.25 2006/05/23 Jeremy Schubert
; This script uses the First name"."last name for account names ; This script uses the phone number of the person as the initial Password ; home dirs are created as \ USERS \ students \ gradexx \ firstname.lastname$ ; ie: I:\users\students\grade10\jane.doe$ ; (account = Jane Doe) ; ; ; ;This script will check For the following: ; that the plant code is three characters long ; check that the OU structure exists to create the user in And that the user running the script can connect to it. ; checks to make sure that the groups the user is to be added to exist ; checks that the directory And file that is to be used to create users exists ; checks to make sure that the log directory and log file exists if not it will create them ; checks to make sure that the home directory path exists ; Checks that the user name does not exceed 20 characters
; checks For the existanace of the user anywhere in the Student Domain ; checks for the existanace of the home drive before creating it ; Checks to see If the Password is 7 characters Or longer
; This script will add the user to the following groups by $default ; GGXXX-INTERNET ; GGXXX-STUDENTS ; GGXXX-GRADEXX ; GG-SECTION06
;SetOption ('Explicit','On') ;If @ERROR <> 0 Then Next On Error Resume Next
; Declare variables Dim $objPLANT Dim $defPLANT Dim $defPLLG Dim $objBAD Dim $objSERV Dim $objSERV1 Dim $objHPATH Dim $objOU Dim $objOU1 Dim $objGROUP1 Dim $objGROUP2 Dim $objGROUP3 Dim $objGROUP4 Dim $objNetwork Dim $defTXTPTH Dim $objTXTPTH Dim $defTEXT Dim $objTEXT Dim $objtxtfile Dim $objTFILE Dim strNextLine Dim $objTXTin Dim $objSTUID Dim $objSNAME Dim $objFNAME Dim $objLNAME Dim $objSUSER Dim $defSUSER Dim $objGrade Dim $objNEWA Dim $defhois Dim $defSTUID Dim $defGrade Dim $objUSERP
Dim $objFSO Dim $objFile Dim $objlogfodler Dim $objLOGFILE Dim $objHOMED Dim $defHOMED Dim $objShare Dim ShareService$obj Dim oDomain Dim oUSER Dim $objPASS Dim $defPASS Dim $defPWLG Dim $objUUPN Dim $defLCHA Dim FS Dim $objUSER Dim $objDNAME Dim NewShare Dim $objShell
Dim $objProfilePath
;These were Dimmed in the original VBS file
;DIM $objGROUP5? ;Dim $objFOLDER ;DIM $objTEXTFILE ;Dim Txtin ;DIM strNEXTLine ;Dim i ;DIM Txtfile ;Dim LOGFolder ;DIM LOGFILE
;I'm not sure how to convert the Const to kix
Const ADS_UF_NORMAL_ACCOUNT = 512 Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8
Const FILE_SHARE = 0 Const MAXIMUM_CONNECTIONS = 5
$objFSO = Create$object ("Scripting.FileSystem$object") FS = Create$object("Scripting.FileSystem$object") $objNetwork = WScript.Create$object("Wscript.Network")
; Have user enter plant code. Used in selectiong Server name and OU structure Do Until $defPLANT = vbYES $objPLANT = Gets ("Please Enter your Plant Code (Must be 3 digits). Enter 999 to exit.", "USER CREATION - PLANT CODE") $defPLANT = MessageBox ("The plant code that you entered is: " + $objPLANT + @crlf + "Is this Correct?", 4) Loop
; check to make sure that the plant code is three characters long $defPLLG = Len($objPLANT) If $defPLLG <> 3 MessageBox ("The plant code that you entered is not three characters long. Existing Program.") Goto end EndIf
; variables as determined by plant code that was entered Select Case $objPLANT Case "047" $objSERV = "\\S047-S0371-01\" $objSERV1 = "S047-S0371-01" Err.Number = 0 $objOU1 = ",OU=047USTUDENTS,OU=047USCHOOL,OU=SECTIONU06,OU=User Accounts,DC=student,DC=xxxx,DC=xx,DC=xx" $objOU = Get$object("LDAP://OU=047USTUDENTS,OU=047USCHOOL,OU=SECTIONU06,OU=User Accounts,DC=student,DC=xxxx,DC=xx,DC=xx") If (Err.Number <> 0) MessageBox "Unable to connect to the OU structure for this school. Existing Program." Goto end EndIf Err.Number = 0 $objGROUP1 = Get$object("LDAP://CN=GG047-INTERNET,OU=047UGROUPS,OU=047USCHOOL,OU=SECTIONU06,OU=User Accounts,DC=student,DC=xxxx,DC=xx,DC=xx") If (Err.Number <> 0) MessageBox "The Group GG047-INTERNET no longer exists. Existing Program." Goto end EndIf Err.Number = 0 $objGROUP2 = Get$object("LDAP://CN=GG047-STUDENTS,OU=047UGROUPS,OU=047USCHOOL,OU=SECTIONU06,OU=User Accounts,DC=student,DC=xxxx,DC=xx,DC=xx") If (Err.Number <> 0) MessageBox "The Group GG047-STUDENTS no longer exists. Existing Program." Goto end EndIf $objHPATH = "users$\students\" If Not FS.FolderExists($objSERV + $objHPATH) MessageBox "The home directory path of " + $objSERV + $objHPATH + " no longer exists. Existing Program." Goto end EndIf ;$objSNAME = "logon047.bat" $objlogfodler = "c:\log" $objLOGFILE = "c:\log\Muser.txt" $objUSERP = "I:\users\students\"
Case "071" $objSERV = "\\S071-S0371-01\" $objSERV1 = "S071-S0371-01" Err.Number = 0 $objOU1 = ",OU=071USTUDENTS,OU=071USCHOOL,OU=SECTIONU02,OU=User Accounts,DC=student,DC=xxxx,DC=xx,DC=xx" $objOU = Get$object("LDAP://OU=071USTUDENTS,OU=071USCHOOL,OU=SECTIONU02,OU=User Accounts,DC=student,DC=xxxx,DC=xx,DC=xx") If (Err.Number <> 0) MessageBox "Unable to connect to the OU structure for this school. Existing Program." Goto end EndIf Err.Number = 0 $objGROUP1 = Get$object("LDAP://CN=GG071-INTERNET,OU=071UGROUPS,OU=071USCHOOL,OU=SECTIONU02,OU=User Accounts,DC=student,DC=xxxx,DC=xx,DC=xx") If (Err.Number <> 0) MessageBox "The Group GG071-INTERNET no longer exists. Existing Program." Goto end EndIf Err.Number = 0 $objGROUP2 = Get$object("LDAP://CN=GG071-STUDENTS,OU=071UGROUPS,OU=071USCHOOL,OU=SECTIONU02,OU=User Accounts,DC=student,DC=xxx,DC=xx,DC=xx") If (Err.Number <> 0) MessageBox "The Group GG071-STUDENTS no longer exists. Existing Program." Goto end EndIf $objHPATH = "users$\students\" If Not FS.FolderExists($objSERV + $objHPATH) MessageBox "The home directory path of " + $objSERV + $objHPATH + " no longer exists. Existing Program." Goto end EndIf $objSNAME = "logon071.bat" $objlogfodler = "c:\log" $objLOGFILE = "c:\log\Muser.txt" $objUSERP = "I:\users\students\"
Case "999" MessageBox "Script terminated by user. Existing Program." Goto end
Case Else MessageBox "The Plant Code that you entered is not recognized by this script. Existing Program." Goto end End Select
; Have user enter path of where the text file is located Do Until $defTXTPTH = vbYES $objTXTPTH = Gets ("Please enter the path of the text file to use " + @crlf + "(e.g. c:\users\students).", "MASS ACCOUNNT CREATION - PATH of TEXT file") $defTXTPTH = MessageBox ("The path of the text file is : " + $objTXTPTH + @crlf + "Is this Correct?", 4) Loop
Do Until $defTEXT = vbYES $objTEXT = Gets ("Please Enter the text file to use (must end in .txt)" + @crlf + "(e.g. users.txt)", "MASS ACCOUNT CREATION - PLANT CODE") $defTEXT = MessageBox ("The text file name that you entered is : " + $objTEXT + @crlf + "Is this Correct?", 4) Loop
$objtxtfile = $objTXTPTH + "\" + $objTEXT
; Check for the existence of the text file that the user entered. If $objFso.FileExists($objtxtfile) MessageBox "Confirmed existance of text file. Press OK to continue." Else MessageBox "The text file you entered does not exist. Existing Program." Goto end EndIf
; create log folder, create log file, If it exists append to the file if not create one. If $objFSO.FolderExists($objlogfodler) If $objFso.FileExists($objLOGFILE) $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteBLANKlines (2) $objFILE.WriteLine "Creating Accounts " + Now $objFile.Close Else $objFILE = $objFSO.CreateTextFile ($objLOGFILE) $objFile.Close $objFILE = $objFSO.OpenTextFile ($objLOGFILE, Forwriting) $objFILE.WriteLine "Creating Accounts " + Now $objFile.Close EndIf Else $objFolder = $objFSO.CreateFolder ($objlogfodler) $objFILE = $objFSO.CreateTextFile ($objLOGFILE) $objFile.Close $objFILE = $objFSO.OpenTextFile ($objLOGFILE, Forwriting) $objFILE.WriteLine "Creating Accounts " + Now $objFile.Close EndIf
; write plant code to log file $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteBLANKlines (2) $objFILE.WriteLine "Accounts will be created for plant code " + $objPLANT $objFILE.WriteBLANKlines (2) $objFile.Close
$objTFILE = $objFSO.OpenTextFile ($objtxtfile, ForReading)
; read each line of the text file one by one and loop until end of file Do Until $objTFILE.AtEndOfStream strNextLine = $objTFILE.ReadLine ; split line into fields and place into 1 dimensional array, assuming txt file ; and comma separated values $objTXTin = Split(strNextLine , ",") ; variables to meaningful names $objSTUID = $objTXTin(0) $objLNAME = $objTXTin(1) $objFNAME = $objTXTin(2) $objGrade = $objTXTin(3) $objPASS = $objTXTin(4) $objSUSER = $objFNAME + "." + $objLNAME $objHOMED = $objLNAME + Left ($objFNAME,1) ; enter account information into log file $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "USER NAME: " + $objSUSER $objFILE.WriteLine "Home Directory: " + $objHOMED $objFile.Close
; check for length of username and home directory $defSUSER=40 Do Until $defSUSER <= 20 $defSUSER = Len($objSUSER) If $defSUSER > 20 $objNEWA = 1 MessageBox ("The length of the User name (" + $objSUSER + ") is to long." + @crlf + "Please enter a shorter username.") $objFNAME = Gets ("Please Enter a new first name for the account (" + $objSUSER + "):", "USER CREATION - FIRST NAME") If $objFNAME = "" MessageBox "You clicked cancel or you left the entry empty. Skipping the creation of this account" $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "SKipping account creation. " $objFile.Close $objNEWA = 0 Exit Do EndIf $objLNAME = Gets ("Please Enter a new last name for the account (" + $objSUSER + "):", "USER CREATION - LAST NAME") If $objLNAME = "" MessageBox "You clicked cancel or you left the entry empty. Skipping the creation of this account" $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "SKipping account creation. " $objFile.Close $objNEWA = 0 Exit Do EndIf EndIf $objSUSER = $objFNAME + "." + $objLNAME $defSUSER = Len($objSUSER) Loop
; write new user name to the log file If $objNEWA = 1 $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "New account name is :" + $objSUSER $objFile.Close EndIf
; Check for existance of user oDomain = Get$object("WinNT://xxxxSTU") oDomain.Filter = Array("user") For Each oUser in oDomain If Lcase(oUser.name) = Lcase($objSUser) ? $objSUser + " already has an account. Skipping the creation of this user" $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "Account already created. SKipping this account. " $objFile.Close Exit Do EndIf Next
; create home drive name from last name and first name $objHOMED = Left ($objLNAME) + Left ($objFNAME) $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The home directory name is :" + $objHOMED $objFile.Close
; check to see if the home directory exists if not create it $defhois = 0 Err.Number = 0 FS.CreateFolder($objSERV + $objHPATH + $objHOMED) If (Err.Number <> 0) $defhois = 1 MessageBox "The directory of :" + $objSERV + $objHPATH + $objHOMED + " already exists." $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The home directory of " + $objHOMED + " already exists." $objFile.Close Err.Number = 0 Else $defhois = 0 $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The home directory of " + $objHOMED + " was sucessfully created." $objFile.Close Err.Number = 0 EndIf
;if the home directory does exist have user enter a new one and check again if it exits Do Until $defhois = 0 Err.Number = 0 $objHOMED = Gets ("Please Enter a new home directory name for the account (" + $objSUSER + "):", "USER CREATION - NEW HOME DIRCTORY NAME") $defHOMED = Len($objHOMED) ; If $defHOMED > 12 ; $defhois = 1 ; MessageBox ("The length of the Home Directory name is: " + $defHOMED + ". This is to long. Try again please.") Else Err.Number = 0 FS.CreateFolder($objSERV + $objHPATH + $objHOMED) If (Err.Number <> 0) MessageBox "The directory of :" + $objHPATH + $objHOMED + " already exists." $defhois = 1 Err.Number = 0 Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The home directory of " + $objHOMED + " was sucessfully created." $objFile.Close $defhois = 0 Err.Number = 0 EndIf EndIf Loop
; check to see if the Student ID is 6 digits long $defSTUID = 7 Do Until $defSTUID = 6 $defSTUID = Len($objSTUID) If $defSTUID <> 6 MessageBox ("The current student ID of: " + $objSTUID + " is invalid for account :" + $objSUSER + ".") $objSTUID = Gets ("Please Enter a new Student ID (Range 000000 to 999999) for the account (" + $objSUSER + "):", "USER CREATION - STUDENT ID") Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The Student ID for account " + $objSUser + " is " + $objSTUID $objFile.Close EndIf Loop
; check to see if the Student Grade is 2 digits long $defGrade = 7 Do Until $defGrade = 2 $defGrade = Len($objGrade) If $defGrade <> 2 MessageBox ("The current student grade of: " + $objGrade + " is invalid for account :" + $objSUSER + ".") $objGRADE = Gets ("Please Enter a new Student Grade (Range 01 to 12) for the account (" + $objSUSER + "):", "USER CREATION - STUDENT GRADE") Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The Grade for account " + $objSUser + " is " + $objGRADE $objFile.Close EndIf Loop
; check to see if the student phone number is 7 digits long $defPASS = 8 Do Until $defPASS = 7 $defPASS = Len($objPASS) If $defPASS <> 7 MessageBox ("The current student phone number of: " + $objPASS + " is invalid for account :" + $objSUSER + ".") $objPASS = Gets ("Please Enter a new Studentnt Phone Number (Range 1111111 to 9999999) for the account (" + $objSUSER + "):", "USER CREATION - STUDENT PHONE NUMBER") Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The Student Phone Number for account " + $objSUser + " is " + $objPASS $objFile.Close EndIf Loop
; create user and attributes $objUUPN = $objSUSER + "@xxxx.ab.ca" $objDNAME = $objFNAME + " " + $objLNAME $objUSER = $objOU.Create("User", "cn=" + $objSUSER) $objUser.Put "SamAccountName", $objSUSER $objUser.Put "UserPrincipalName", $objUUPN $objUser.Put "GivenName", $objFNAME $objUser.Put "sn", $objLNAME $objUser.Put "DisplayName" , $objDNAME $objUser.Put "Description", "Student User Account" $objUser.Put "l", "Calgary" $objUser.Put "st", "AB" $objUser.Put "c", "CA" $objUser.Put "co", "Canada" $objUser.Put "HomeDirectory", $objSERV + $objHOMED + "$" $objUser.Put "HomeDrive", "H:" $objUser.Put "scriptpath", $objSNAME ; $objUser.Put "ProfilePath", $objProfilePath? Err.Number = 0 $objUser.Info If (Err.Number <> 0) MessageBox "There Was problems in creating the user. Please check Active Directory User and Computers " + @crlf + "for the account and correct any problems there." $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "There were errors in creating the account : " + $objSUSER + ". Please check AD Users and computers." $objFile.Close Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The Account : " + $objSUSER + " was successfully created." $objFile.Close EndIf $objUser.Password($objPASS) $objUser.AccountDisabled = 0 $objUser.Info $objUser.Put "pwdLast", 0 Err.Number = 0 $objUser.Info If (Err.Number <> 0) MessageBox "There Was problems in creating the user. Please check Active Directory User and Computers " + @crlf + "for the account and correct any problems there." $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "There were errors in creating the account : " + $objSUSER + ". Please check AD Users and computers." $objFile.Close Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The Account : " + $objSUSER + " was successfully activated and password was ." $objFile.Close EndIf
; sleep for 3 seconds to give the system time to create the account before adding it to groups Sleep 20000
; add user to the $default groups Err.Number = 0 $objGROUP1.Add("LDAP://cn=" + $objSUSER + $objOU1) If (Err.Number <> 0) MessageBox "There Was a problem in adding the user: " + $objSUSER + " to the Internet group for your school." + @crlf + "Please check Active Directory User and Computers for the account and correct any problems there." $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "There was an error in adding the user : " + $objSUSER + " to the Internet group for school " + $objPLANT $objFile.Close Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The user: " + $objSUSER + " was successfully added to the Internet Group for school " + $objPLANT $objFile.Close EndIf
Err.Number = 0 $objGROUP2.Add("LDAP://cn=" + $objSUSER + $objOU1) If (Err.Number <> 0) MessageBox "There Was a problem in adding the user: " + $objSUSER + " to the General Student group for your school." + @crlf + "Please check Active Directory User and Computers for the account and correct any problems there." $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "There was an error in adding the user : " + $objSUSER + " to the General Student group for school " + $objPLANT $objFile.Close Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The user: " + $objSUSER + " was successfully added to the General Student Group for school " + $objPLANT $objFile.Close EndIf $objShell = Create$object("Wscript.Shell") ;add to other groups
;share home drive and make it hidden Err.Number = 0 $objShare = $objHOMED + "$" $objUDIR = $objUSERP + $objHOMED $objWMIService = Get$object("winmgmts:"& "{impersonationLevel=impersonate}!\\" + $objSERV1 + "\root\cimv2") $objNewShare = $objWMIService.Get("Win32_Share") errReturn = $objNewShare.Create ($objUDIR, $objShare, FILE_SHARE, MAXIMUM_CONNECTIONS, "Shared by Remote Command.") ;$objshell.Run "rmtshare.exe " + $objserv + $objshare + " = "& $objUSERP + $objhomed + " /users:1" ;IF (Err.Number <> 0) ; MessageBox "There Was a problem in creating the share: " + $objShare + " for the user: " + $objSUSER + @crlf + "Please check the file server for your school to correct the problem" ; $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) ; $objFILE.Writeline "There Was a problem in creating the share: " + $objShare + " for the user: " + $objSUSER + ". Please check the file server for your school to correct the problem" ; $objFile.Close ;ELSE ; $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) ; $objFILE.Writeline "The share: " + $objShare + " was successfully created for the user: " + $objSUSER + "." ; $objFile.Close ;EndIf
; share permisssions Err.Number = 0 ; add local Administrators to the share with full control permissions $objShell.Run "acl.exe -on " + $objSERV + $objShare + " -ot shr -actn ace -ace n:" + $objSERV1 + "\administrators:p:full -silent" $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteBLANKlines (1) $objFile.Close If (Err.Number <> 0) MessageBox "There Was a problem in adding the administrators group to the permissions on the share: " + $objShare + @crlf + "Please check the file server for your school to correct the problem" $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "There Was a problem in adding the administrators group to the permissions on the share: " + $objShare + "Please check the file server for your school to correct the problem" $objFile.Close Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The Administrators group was successfully added to the share: " + $objShare $objFile.Close EndIf Sleep 3000
Err.Number = 0 ; add the local group LGXXX-HOMEDIR to the share with full control permissions $objShell.Run "acl.exe -on " + $objSERV + $objShare + " -ot shr -actn ace -ace n:" + $objSERV1 + "\LG" + $objPLANT + "-HOMEDIR:p:full -silent" $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteBLANKlines (1) $objFile.Close If (Err.Number <> 0) MessageBox "There Was a problem in adding the LG" + $objPLANT + "-HOMEDIR group to the permissions on the share: " + $objShare + @crlf + "Please check the file server for your school to correct the problem" $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "There Was a problem in adding the LG" + $objPLANT + "-HOMEDIR group to the permissions on the share: " + $objShare + "Please check the file server for your school to correct the problem" $objFile.Close Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The LG" + $objPLANT + "-HOMEDIR group was successfully added to the share: " + $objShare $objFile.Close EndIf Sleep 3000 Err.Number = 0 ; add the user account to the share with change permissions $objShell.Run "acl.exe -on " + $objSERV + $objShare + " -ot shr -actn ace -ace n:xxxxstu\" + $objSUSER + ":p:change -silent" $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteBLANKlines (1) $objFile.Close If (Err.Number <> 0) MessageBox "There Was a problem in adding " + $objSUSER + " to the permissions on the share: " + $objShare + @crlf + "Please check the file server for your school to correct the problem" $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "There Was a problem in adding " + $objSUSER + " to the permissions on the share: " + $objShare + "Please check the file server for your school to correct the problem" $objFile.Close Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The user: " + $objSUSER + " was successfully added to the share: " + $objShare $objFile.Close EndIf Sleep 3000
Err.Number = 0 ;remove the everyone group from the share $objShell.Run "acl.exe -on " + $objSERV + $objShare + " -ot shr -actn trustee -trst n1:Everyone:ta:remtrst:w:dacl -silent" $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteBLANKlines (1) $objFile.Close If (Err.Number <> 0) MessageBox "There Was a problem in removing the Everyone group from the permissions on the share: " + $objShare + @crlf + "Please check the file server for your school to correct the problem" $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "There Was a problem in removing the Everyone group from the permissions on the share: " + $objShare + "Please check the file server for your school to correct the problem" $objFile.Close Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The Everyone group was successfully removed from the share: " + $objShare $objFile.Close EndIf Sleep 3000
; change directory permissions $objShell.Run "acl.exe -on " + $objSERV + $objHPATH + $objHOMED + " -ot file -actn ace -ace n:xxxxstu\" + $objSUSER + ":p:change" $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteBLANKlines (1) $objFile.Close If (Err.Number <> 0) $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "There Was a problem in adding the user account to the permissions on the home directory: " + $objHOMED + "Please check the file server for your school to correct the problem" $objFile.Close Else $objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteLine "The user account was successfully added to the home directory: " + $objHOMED $objFile.Close EndIf Sleep 3000
$objFILE = $objFSO.OpenTextFile ($objLOGFILE, ForAppending) $objFILE.WriteBLANKlines (2) $objFile.Close Sleep 5000
$objNEWA = 0 $defhois = 0 $objSTUID = "" $objLNAME = "" $objFNAME = "" $objGrade = "" $objPASS = "" $objSUSER = "" $objHOMED = ""
Loop
:End ;That's all there is folks!
_________________________
--- Bishop Grandin Technology Department 'Either we're on time, or we're late'
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 778 anonymous users online.
|
|
|