Home » Scripting » Help needed with modifications Messages in this topic - RSS
|
7/24/2013 12:34:38 PM
trousdalec
trousdalec
Posts 1
I work in the Technology Department of a small school district and I was tasked a few years ago with writing scripts to create student accounts each year.

I am working with a csv file exported from our Student Information System (SIS) that contains their Student ID number, First Name, Last Name, Middle Name, Grade level and Campus number.

In previous years I just deleted all of the student accounts at each campus and started fresh each year with new accounts, but now we are using Google Apps for Education (GAFE) which creates accounts each night based off of specific OU's in AD. If I wipe the accounts and run the script the same day, the GAFE accounts are not deleted. However, if I delete the accounts in AD on one day and the script runs after the GAFE script checks AD it will delete their GAFE accounts including any files and emails.

I'd like to change how we are running the script and have it run every day to pick up new students that have enrolled in the district or changed campuses within the district and this is part of where I run into my problems. I can generate a new csv file each night from our SIS so that I'll have current enrollment data to run the script from. We have always had problems getting people on campus to let us know when new students are enrolled so that we can create their accounts so I want to run the script each night but not affect existing accounts if they are on the correct campus and in the correct group. I don't know how to have it check to see if an account already exists and skip that user IF they are in the correct OU and groups. The OU and groups are based on the campus the student is enrolled at.

If the user exists but is in the wrong OU and group I want to move the user to the correct OU, remove them from the old campus group and add them to the new campus group.

If the user exists and is in the correct OU and group I want to move to the next student in the csv file without doing anything to the users account.

If the user does not exist I want the script to continue and create the user account and add them to the correct group.

I have done a bit of modification to my existing script below and I'm marking those lines in red text. Those lines may need modification as well since adding the students to groups through the script is new to me.

Any assistance would be appreciated.

'==========================================================================
'LANG : VBScript
'NAME : CreateCCISDStudents.vbs
'AUTHOR : Curtis M. Trousdale
'DATE : 06/18/2013
'Description : Create Student User Accounts in Active Directory from CCISDUsernames.csv file
'COMMENT : New - Add Group Membership
'
'
'==========================================================================
'==========================================================================
'Variable Declarations



strSheet = "\\tech01\Holding\Schools\CHS\Scripts\vbs\Students\CCISDUsernames.csv"
strPWD = "sandcrab"

'get distinguished name of the domain
Set objRoot = GetObject("LDAP://RootDSE")
strDomainPath = objRoot.Get("DefaultNamingContext")



' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
dtmThisDay = Day(Date)
dtmThisMonth = Month(Date)
dtmThisHour = hour(time)
dtmThisMinute = minute(time)
strBackupName = dtmThisMonth & "_" & dtmThisDay & "_" & dtmThisHour & "_" & dtmThisMinute

'Set objOutFile = objFso.OpenTextFile("\\tech01\Holding\Schools\CHS\Scripts\vbs\" & strBackupName & "ADLOG.txt", 8, True)
const ADS_PROPERTY_APPEND = 3

intRow = 3 'Row 1 contains headings and Row 2 contains reference numbers

' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in strSheet
' Note Right("000000"&Trim(#),6) is to force a 6 digit number with leading zeroes
Do Until objExcel.Cells(intRow,1).Value = ""
strSam = Right("000000"&Trim(objExcel.Cells(intRow, 1).Value),6)
strCN = strSam
strFirst = Trim(objExcel.Cells(intRow, 3).Value)
strLast = Trim(objExcel.Cells(intRow, 2).Value)
strDisp = Trim((objExcel.Cells(intRow, 3).Value)&" "&(objExcel.Cells(intRow, 2).Value))
strGrade = Trim(objExcel.Cells(intRow, 5).Value)

'Set OU Path and Group Path
Select case objExcel.Cells(intRow, 6).value
case "1"
OUVar = "ou=Students, ou=CHS, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"
GroupVar = "cn=CHS_Students, ou=CHS, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"

case "3"
OUVar = "ou=Students, ou=HHS, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"
GroupVar = "cn=HHS_Students, ou=HHS, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"

case "4"
OUVar = "ou=Students, ou=HHS, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"
GroupVar = "cn=HHS_Students, ou=HHS, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"

Case "43"
OUVar = "ou=Students, ou=TRA, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"
GroupVar = "cn=TRA_Students, ou=TRA, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"

Case "101"
OUVar = "ou=Students, ou=HJM, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"
GroupVar = "cn=HJM_Students, ou=HJM, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"

case "102"
OUVar = "ou=Students, ou=JRE, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"
GroupVar = "cn=JRE_Students, ou=JRE, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"

case "105"
OUVar = "ou=Students, ou=POC, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"
GroupVar = "cn=POC_Students, ou=POC, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"

Case "107"
OUVar = "ou=Students, ou=SEA, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"
GroupVar = "cn=SEA_Students, ou=SEA, ou=Schools, ou=ccisdusers, dc=yaddayadda, dc=net"

End Select

' Build the actual User from data in strSheet.
Set objContainer=GetObject("LDAP://" & OUVar)
Set ObjGroup=GetObject("LDAP;//" & GroupVar)
Set objUser = objContainer.Create("User", "cn=" & strCN)
objUser.sAMAccountName = strSam
objUser.userPrincipalName = strSam & "@yaddayadda.net"
objUser.givenName = strFirst
objUser.sn = strLast
objUser.DisplayName = strDisp
objUser.Description = strGrade
objUser.SetInfo
objUser.SetPassword strPWD
objUser.AccountDisabled = False
objUser.Put "PwdLastSet", 0
objUser.SetInfo
objGroup.add(objUser.ADsPath)


On Error GoTo 0
End If

End If



intRow = intRow + 1

Loop

objExcel.Quit

WScript.Quit
edited by trousdalec on 7/24/2013
edited by trousdalec on 7/24/2013
2/9/2020 5:58:31 PM
Janet23
Janet23
Posts 1
Yes, there is modification need for the dissertation help but can you send me the more samples about the same so I can modified it in more natural way though and there would not be any error found when you may put it in another applications that sounds amazing.
so kindly let me know about it if I know do it for you without making more changes.
pages: 1
|

Home » Scripting » Help needed with modifications