Section for Scripting Users with VBScript
This page acts as a mini-sitemap to list all the scripts which deal with users. My philosophy is to produce a collection of scripts each with a clear goal. What you can do is take sections of each script and adapt the code to solve for your specific problem.
- Create User a user in Active Directory
- Create a batch of users with info in a spreadsheet
- Create a user with a mailbox
- Setting the UserAccountControl attribute
- Simple script to set users’ passwords
- Force users to change their passwords with pwdLastSet
Extra VBScripts in Ezine Section
- Ezine 103 Create Users
- Ezine 23 Enable Accounts
- Ezine 86 LastLogon
- Ezine 84 Acctinfo
- Ezine 23b UserAccountValues – Useful Reference
- Ezine 93 ADSI Edit
- Ezine 102 Binding to AD
Pure VBScript Techniques – Can be adapted for other scripts
- ObjOU.Create You can deploy the .create method or many AD objects.
- ObjUser.Put and objUser.SetInfo Useful commands to set properties
- Do Until…. Loop. Classic structure to cycle through spreadsheet cells.
- For Each… In … Next Here is a variation on the simple For…. Next loop.
Import users from a spreadsheet. Just provide a list of the users with their fields in the top row, and save as .csv file. Then launch this FREE utility and match your fields with AD’s attributes, click and import the users.
Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.
If you need more comprehensive software, download a free trial of SAM (Server & Application Monitor)
VBScript conforms to the classic Object programming model. Objects such as Users have properties for example ‘givenName’ and ‘description’. The most interesting part is the methods because they are used to manipulate the object, for instance, GetObject, CreateObject and ConnectObject. More often than not, the goal of our script is to set a value for a particular properties, for example Object = User, Property = givenName, Value = Guy.
It can be hard to pin down VBScript. There are no stand-alone executables, you do not compile VBScript as you would with C++. How does it work, I can hear you asking. Well VBScript works through a host WSH which reads plain scripts, compiles them and runs them. This means what ever is in those scripts is what gets done.
Script to Create a User in a Named OU (Organizational Unit)
‘ Users .vbs
‘ Sample VBScript to create a User in Users .
‘ Author Guy Thomas http://Computerperformance.co.uk/
‘ Version 1.3 – September 2010
Dim objRootLDAP, objContainer, objNewUser
strUser = "DomGuy2"
‘ Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Users," & _
‘ Build the actual User.
Set objNewUser = objContainer.Create("User", "cn=" & strUser)
objNewUser.Put "sAMAccountName", strUser
‘ End of free sample Create Users VBScript.
If you like this page then please share it with your friends