Basically what I need to be able to do is run a script that reads a tab delimited file, parses the fields and then uses those fields to perform various functions (mattering on the script). If I can get the first one working, I think that the rest will be relatively elementary to adjust to do what I need them to do. This first snippet of code is HORRIBLE. I've been trying to get it working for ages now (ok... a week and a half, give or take... it just seems like ages), so I figure I'll ask some people who might be able to help me.
Expand|Select|Wrap|Line Numbers
- Module modUserCreation
- Const ForReading = 1
- Const ForWriting = 2
- Const ForAppending = 8
- Const TriStateUseDefault = -2
- Public LogFilename
- Public strprefix
- Public Sub Main()
- Dim strmsg As String
- Dim x As Object
- Dim struserid As String
- Dim strfname As String
- Dim strsname As String
- Dim strminit As String
- Dim strdname As String
- Dim strdescr As String
- Dim strcontainer As String
- Dim strpaswd As String
- Dim strdomain As String
- Dim strdomainsuffix As String
- Dim record As String
- Dim strfilename As String
- strfilename = InputBox("Enter user list file name")
- strdomain = InputBox("Enter Domain Name ex: Microsoft, Google")
- strdomainsuffix = InputBox("Enter DNS suffix for domain ex: com, local")
- FileOpen(1, My.Application.Info.DirectoryPath & "\" & strfilename, OpenMode.Input)
- While Not EOF(1)
- record = LineInput(1)
- x = Split(record, vbTab)
- strcontainer = Trim(x(0)) 'This is the name of the OU that the user object will be created in
- struserid = Trim(x(1)) 'UserID (logon name) field - should validate before submitting, must be unique
- strfname = Trim(x(2)) 'User First Name
- strsname = Trim(x(3)) 'User Last (sur)Name
- strminit = Trim(x(4)) 'User Middle Initial
- strdname = Trim(x(5)) 'Display Name (probably want to create an option on order or fname, sname and minit
- strdescr = Trim(x(6)) 'Description field
- strpaswd = Trim(x(7)) 'Password - probably want to eventually turn this into a random typable set of characters
- 'Time to create the user with the fields pulled in from the text file (possibly pull the data from text input)
- objParent = strcontainer
- objUser = objParent.Create("user", "cn=" & struserid)
- objUser.Put("sAMAccountName", struserid) 'Set sAMAccountName field
- objUser.Put("userPrincipalName", struserid & "@" & strdomain & "." & strdomainsuffix)
- objUser.Put("givenName", strfname) 'First name
- objUser.Put("sn", strsname) 'surname
- objUser.Put("displayName", strsname & ", " & strfname & " " & strminit)
- objUser.Put("mname", strminit)
- objUser.SetInfo()
- objUser.SetPassword(strpaswd)
- objUser.AccountDisabled = False
- objUser.SetInfo()
- objUser.Put("userAccountControl", 512)
- objUser.SetInfo()
- End While
- FileClose(1)
- End Sub
- End Class
- End Module
BTW... yes, I know I have some really boneheaded errors in here, I think some are the result of several edits accidentally removing required items.
I can create the user object when I explicitly define the variables (or provide input boxes), but when I try to do it with input from a file, it flakes out on me.