Tech Support > Operating Systems > Windows 2000 > Create Users VBS
Create Users VBS
Posted by Pegasus \(MVP\) on July 20th, 2003



"Risrollout" <risrollout@hotmail.com> wrote in message
news:#K4vxhjTDHA.3132@tk2msftngp13.phx.gbl...
Why not keep it simple and use a batch file to create your
new users?

net user JSmith welcome /add /comment:"Student" /fullname:"Jack Smith"
/scriptpath:student.bat

The same line could be written as

net user %3 welcome /add /comment:"%4" /fullname:"%1 %2"
/scriptpath:student.bat

provided that you had a text file of the form

Jack Smith JSmith Student

that you would use a list file to feed your batch file.




Posted by Michael Holzemer on July 20th, 2003


http://www.aspfaq.com/5003
news:Oa$4Y$kTDHA.2280@TK2MSFTNGP12.phx.gbl...

--
Regards,

Michael Holzemer
No email replies please - reply in newsgroup

Learn script faster by searching here
http://www.microsoft.com/technet/tre...er/default.asp


"Pegasus (MVP)" <I.can@fly.com> wrote in message
news:uhxz0NlTDHA.1288@tk2msftngp13.phx.gbl...


Posted by Risrollout on July 20th, 2003


??? I am using Adduser.bat from the W2k resource kit now. I am trying to
find a way to add the users to the proper OU and security group in one pass
instead of loading them to the User OU, then having to go in and move then
to the proper OU and then add them to the security group and so on. With
CreateUser.vbs you are suppose to be able to add them to the proper OU and
security group, but I don't know how to set up the CSV file to have the rows
of attributes be in correct order.
Take for instance the Adduser.bat input file is set up like this.
[Users],,,,,,,,
First.Last,First Last,Last 4 SSN,EmployeeID
Joe.Doe, Joe Doe,1234,12587
Jane.Doe,Jane Doe,4567,78945

The command line switches look like this.
Addusers /c c:\classddmmyy.csv /p:e
So back to my question; How do you structure the CSV input file for
CreateUsers.vbs?
What I have currently is.

strUsrDN:Joe.Doe,strFirstName:Joe,strLastameoe,s trPassword:1234,strOU:"Cla
ss D1"\Training\"User Accounts",StrDNSDomain:Mydomain.MyCodomain.com

The error I get is Improper syntax: Can not read Classddmmyy.csv.




"Pegasus (MVP)" <I.can@fly.com> wrote in message
news:uhxz0NlTDHA.1288@tk2msftngp13.phx.gbl...


Posted by Michael Holzemer on July 20th, 2003


Did you look at your other post. I tailored the script to you.

--
Regards,

Michael Holzemer
No email replies please - reply in newsgroup

Learn script faster by searching here
http://www.microsoft.com/technet/tre...er/default.asp


"Risrollout" <risrollout@hotmail.com> wrote in message
news:%23Ti7d0lTDHA.2196@TK2MSFTNGP12.phx.gbl...


Posted by Michael Holzemer on July 20th, 2003


Absolutely

--
Regards,

Michael Holzemer
No email replies please - reply in newsgroup

Learn script faster by searching here
http://www.microsoft.com/technet/tre...er/default.asp


"Risrollout" <risrollout@hotmail.com> wrote in message
news:ezqN7DmTDHA.3700@tk2msftngp13.phx.gbl...


Posted by Michael Holzemer on July 20th, 2003


Here is the script with the group part added. I broke it up into 3 areas so
it would be easier to understand. There is the main part of the script that
reads the file, gets the user information then calls the sub routines. The
sub routines are to create the user and then add the user to a group. This
illustrates how you can make the code reusable and much easier to read. You
will need to edit the mydomain part and make sure the file path to the csv
file is correct. In addition I left out error handling, so if an error
occurs it will give a line number and description of the error (along with
the what the heck does that mean information).
You may want to download a color editor so reading will become even easier.
I use the free VBSEditor from Koan www.koansoftware.com to write scripts.
There are two files on the W2K CD that are invaluable for scripting
vbscrip5.chm and wsh.chm. There are many sites that have prewritten scripts
that you can piece together like http://cwashington.netreach.net/main. If
you need help with scripting post in
microsoft.public.windows.server.scripting.

Oh yeah and be sure to see the link in my signature.

'// This keeps me honest
Option Explicit
Dim aLine, sLine, sCN, sLogon, sPass
Dim oTF, oFSO, oOU, oUser, oGroup
'// Constants make the code more readable
Const ForReading = 1

'// Bind to the filesystem object
Set oFSO = CreateObject("Scripting.FileSystemObject")
'// Open up the csv file. Make sure the path here is correct
Set oTF = oFSO.OpenTextFile("C:\book1.csv",ForReading,True)

'// Run a Loop to read all the lines in the file
Do While oTF.AtEndOfStream <> True
'// Read a line of the file
sLine = oTF.ReadLine
'// Create an array split on commas
aLine = split(sline, ",",-1,1)
'// Set the variables
sLogon = aLine(0)
sCN = aLine(1)
sPass = aLine(2)
'// Call the Create User routine
CreateaUser
'// Call the add to Group routine
Add2Group
Loop
Msgbox "Script complete.",vbinformation, "Add Users"
Set oTF = Nothing
Set oFSO = Nothing
Set oUser = Nothing
Set oGroup = Nothing
Set oOU = Nothing

Sub CreateaUser()

'// Bind to the OU where we want to add users
Set oOU = GetObject _
("LDAP://ou=Class D1,ou=Training,ou=User
Accounts,dc=MyDomain,dc=Codomain,dc=com")
Set oUser = oOU.Create("user", "cn=" & sCN)
oUser.put "sAMAccountName", lcase(sLogon)
oUser.put "DisplayName", sCN
'// Need to commit this to AD before adding the password
oUser.SetInfo

oUser.SetPassword sPass
oUser.AccountDisabled = False
oUser.SetInfo

End Sub

Sub Add2Group()

Const ADS_PROPERTY_APPEND = 3
Set oGroup = GetObject _
("LDAP://cn=ClassD1,ou=Class D1,ou=Training,ou=User
Accounts,dc=MyDomain,dc=Codomain,dc=com")
oGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn=" & sCN & ",ou=Class D1,ou=Training,ou=User
Accounts,dc=MyDomain,dc=Codomain,dc=com")
oGroup.SetInfo

End Sub

--
Regards,

Michael Holzemer
No email replies please - reply in newsgroup

Learn script faster by searching here
http://www.microsoft.com/technet/tre...er/default.asp


"Risrollout" <risrollout@hotmail.com> wrote in message
news:ezqN7DmTDHA.3700@tk2msftngp13.phx.gbl...


Posted by Risrollout on July 20th, 2003


Thank you so much for your help. One more question, I have had trouble with
from the start. The input csv file structure. ( might be a stupid question,
but for some reason it just not clear to me) If I read your program right
the file should be set up like this. No header line, so the first line
should be Logon name,Display Name and then password? I.e.
Joe.Doe,Joe Doe,1234
Is that correct?

"Michael Holzemer" <ms2kguru@noway.pacbell.net> wrote in message
news:OSmdzstTDHA.2180@TK2MSFTNGP10.phx.gbl...


Posted by Michael Holzemer on July 20th, 2003


Exactly.


--
Regards,

Michael Holzemer
No email replies please - reply in newsgroup

Learn script faster by searching here
http://www.microsoft.com/technet/tre...er/default.asp


"Risrollout" <risrollout@hotmail.com> wrote in message
news:%23R2GnuuTDHA.2220@TK2MSFTNGP11.phx.gbl...



Similar Posts