bookouri:
Here's a script i wrote (and modified a bit for you). I think it'll help.
To run it, cut and paste all the code into notepad, and save as a file with a .vbs extension (eg. AddUsersComputers.vbs)
To run, just double-click.
This script creates users and/or computers in the deafult users and computers container:
''''''''''''''''''''''''''''''''''''''
'Written by Andrew Levine - 2/2005
''''''''''''''''''''''''''''''''''''''
'This script will add users or computers to active directory.
'Program will repeat until a field is left blank or cancel is pressed
'set Fully Qualified Domain Name
FQDomainName="INSERT FQ DOMAIN NAME" 'this will be after the @ in the user principal name
defaultPassword = "INSERT PASSWORD"
Set objRootDSE = GetObject("LDAP://rootDSE")
'Set OU in which to add Computers (from the bottom up)
Set computerOU = GetObject("LDAP://cn=Computers," & objRootDSE.Get("defaultNamingContext"))
'Set OU in which to add Users
Set userOU = GetObject("LDAP://cn=Users," & objRootDSE.Get("defaultNamingContext"))
sub addComputer (name)
strComputer = name
Const ADS_UF_PASSWD_NOTREQD = &h0020
Const ADS_UF_WORKSTATION_TRUST_ACCOUNT = &h1000
Set objComputer = computerOU.Create("Computer", "cn=" & strComputer)
objComputer.Put "sAMAccountName", strComputer & "$"
objComputer.Put "userAccountControl", _
ADS_UF_PASSWD_NOTREQD Or ADS_UF_WORKSTATION_TRUST_ACCOUNT
objComputer.SetInfo
end sub
sub addUser(shortName, firstname, lastname, description)
Set usr = userOU.Create("user", "CN=" & firstname & " " & lastname)
usr.Put "sAMAccountName", ShortName
usr.Put "userPrincipalName", shortName & "@" & FQDomainName
usr.Put "GivenName", firstname
usr.Put "Sn", lastname
usr.Put "description", description
usr.Put "displayName", firstname & " " & lastname
usr.SetInfo
usr.SetPassword defaultPassword
usr.AccountDisabled = False
usr.SetInfo
end sub
done=0
Sub checkEmpty (userInput)
If userInput = "" Then
Wscript.quit
End if
End sub
Sub addComputers
While done=0
cn = InputBox ("Enter computer to add. Leave blank to exit.", "Add Computers")
checkEmpty cn
addComputer cn
Wend
End Sub
Sub addUsers
While done=0
sn = InputBox ("Enter User ID:", "New User - Leave blank to exit.")
checkEmpty sn
fn = InputBox ("Enter First Name:", "New User - Leave blank to exit.")
checkEmpty fn
ln = InputBox ("Enter Last Name:", "New User - Leave blank to exit.")
checkEmpty ln
de = InputBox ("Enter Description:", "New User - Leave blank to exit.")
checkEmpty de
addUser sn, fn, ln, de
Wend
End Sub
message = "Please pick an option:" & vbCrLf & _
"(Press cancel or leave blank to quit.)" & vbCrLf & vbCrLf & _
"1 - Add Users" & vbCrLf & _
"2 - Add Computers" & vbCrLf & _
"3 - Skip These Menus" & vbCrLf & _
vbCrLf & vbCrLf & "Please enter a number:"
Do
userChoice = InputBox(message, "Add Users & Computers")
select case userChoice
case "1"
addUsers
case "2"
addComputers
case "3"
massUpdate
case ""
WScript.Quit
case else
msgbox "Invalid entry. Please try again."
end select
loop while userChoice <> "" and userChoice <> "0"
Sub massUpdate
'addUser "userID", "fName", "lName", "description"
'addComputer "Computer1"
Wscript.quit
End Sub