Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

USing scripts to add multiple users

Status
Not open for further replies.

Herrona

Technical User
Joined
Jul 24, 2002
Messages
2
Location
GB
I am new to Server 2000 and have witten a VBscript to add all the user info to a new user that I need for the moment, I thought I would be clever and mail-merge the script to a spreadsheet so I could add all the users at once, The script works perfectly as long as I only add one user at a time, kind of defeats the point, How do I modify the following script to allow it to run again for the next users?

Set objOU = GetObject("LDAP://OU=«Organisational_Unit»,dc=«DomainName»,dc=«netaddress»")
Set objUser = objOU.Create("User", "cn=«Username»")
objUser.Put "sAMAccountName", "«Username»"
objUser.SetInfo
Set objUser = GetObject _
("LDAP://cn=«Username»,ou=«Organisational_Unit»,dc=«DomainName»,dc=«netaddress»")
objUser.SetPassword "«Password»"
Set objUser = GetObject _
("LDAP://cn=«Username»,ou=«Organisational_Unit»,dc=«DomainName»,dc=«netaddress»")
objUser.AccountDisabled = FALSE
objUser.SetInfo
Const ADS_PROPERTY_UPDATE = 2
Set objUser = GetObject _
("LDAP://cn=«Username»,ou=«Organisational_Unit»,dc=«DomainName»,dc=«netaddress»")
objUser.Put "userPrincipalName", "«Username»@«DomainName».«netaddress»"
objUser.Put "givenName", "«FirstName»"
objUser.Put "initials", "«Initials»"
objUser.Put "sn", "«Surname»"
objUser.Put "displayName", "«Surname», «FirstName»"
objUser.Put "telephoneNumber", "«Telephone»"
objUser.Put "mail", "«email»"
objUser.Put " " ;;
objUser.AccountExpirationDate = "01/01/1970"
objUser.PutEx ADS_PROPERTY_UPDATE, _
"description", Array("«description»")
objUser.SetInfo
Set objUser = GetObject _
("LDAP://cn=«Username»,ou=«Organisational_Unit»,dc=«DomainName»,dc=«netaddress»")
objUser.Put "profilePath", "\\«servername»\Profiles$\«Username»"
objUser.Put "scriptPath", "«scriptname»"
objUser.Put "homeDirectory", "\\«servername»\«Username»"
objUser.Put "homeDrive", "«homedrive»"
objUser.SetInfo
Set objUser = GetObject _
("LDAP://cn=«Username»,ou=«Organisational_Unit»,dc=«DomainName»,dc=«netaddress»")
objUser.Put "streetAddress", "«address_1»" & _
VbCrLf & "«localarea»"
objUser.Put "l", "«town»"
objUser.Put "st", "«county»"
objUser.Put "postalCode", "«postcode»"
objUser.Put "c", "«country»"
objUser.SetInfo
Set obj«Username» = CreateObject("Scripting.FileSystemObject")
Set objFolder = obj«Username».CreateFolder("D:\users\«Yeargroup»\«Username»")
Const FILE_SHARE = 0
Const MAXIMUM_CONNECTIONS = 5
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewShare = objWMIService.Get("Win32_Share")
errReturn = objNewShare.Create _
("D:\users\«Yeargroup»\«Username»", "«Username»", FILE_SHARE, _
MAXIMUM_CONNECTIONS, "«sharedescription»")
Wscript.Echo errReturn

Note the <<TEXT>> parts are merge fields
if there is one user in the spreadsheet this works but more than one and it fails, Please help.

The script was compiled from the sample scripts downloadable at microsofts Script Center
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top