OK, I am going to preface this by saying I'm very new to VB coding (or any other kind, for that matter), but know a lot about Windows, AD and Security. We are making adjustments to our environment and someone needs to adjust our scripts. I've got a lot of the books and the information that I need to do some of the items is in there. I'm just trying to put it together.
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.
[CODE=vbnet]Module modUserCreation
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const TriStateUseDefa ult = -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.DirectoryP ath & "\" & 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.Creat e("user", "cn=" & struserid)
objUser.Put("sA MAccountName", struserid) 'Set sAMAccountName field
objUser.Put("us erPrincipalName ", struserid & "@" & strdomain & "." & strdomainsuffix )
objUser.Put("gi venName", strfname) 'First name
objUser.Put("sn ", strsname) 'surname
objUser.Put("di splayName", strsname & ", " & strfname & " " & strminit)
objUser.Put("mn ame", strminit)
objUser.SetInfo ()
objUser.SetPass word(strpaswd)
objUser.Account Disabled = False
objUser.SetInfo ()
objUser.Put("us erAccountContro l", 512)
objUser.SetInfo ()
End While
FileClose(1)
End Sub
End Class
End Module[/CODE]
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.
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.
[CODE=vbnet]Module modUserCreation
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const TriStateUseDefa ult = -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.DirectoryP ath & "\" & 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.Creat e("user", "cn=" & struserid)
objUser.Put("sA MAccountName", struserid) 'Set sAMAccountName field
objUser.Put("us erPrincipalName ", struserid & "@" & strdomain & "." & strdomainsuffix )
objUser.Put("gi venName", strfname) 'First name
objUser.Put("sn ", strsname) 'surname
objUser.Put("di splayName", strsname & ", " & strfname & " " & strminit)
objUser.Put("mn ame", strminit)
objUser.SetInfo ()
objUser.SetPass word(strpaswd)
objUser.Account Disabled = False
objUser.SetInfo ()
objUser.Put("us erAccountContro l", 512)
objUser.SetInfo ()
End While
FileClose(1)
End Sub
End Class
End Module[/CODE]
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.
Comment