Scripting Users with VBScript

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.

VBScript Section


Extra VBScripts in Ezine Section

Pure VBScript Techniques – Can be adapted for other scripts

Guy Recommends:  SolarWinds’ Free Bulk Import ToolFree Download Solarwinds Bulk Import Tool

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 Background

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
‘ Version 1.3 – September 2010
‘ ——————————————————‘
Option Explicit
Dim strUser
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


See Also

VBScript CACLS   • VBScript CACLS Excel  •VBScript to Create Folders

WMI Examples   • CACLS Commands   • PowerShell Set ACL

Free WMI Monitor  • WMI PowerShell  • Free SolarWinds Permissions Analyzer