Creating a User with VBScript

VBScript is a scripting language that supports the automation of administrative tasks on all current versions of Windows. VBScript files are text files which can be edited with Notepad or a script editor and saved with a .vbs extension. To execute a script, you can double-click it, which opens the script, using Wscript.exe. Alternatively, from the command line, you can run the script with Cscript.exe, using the following syntax: cscript.exe scriptname

Use the buttons below to navigate through the lesson


Both Wscript.exe and Cscript.exe are components of the Windows Scripting Host (WSH), which is the automation framework installed on all current versions of Windows that support scripting languages, including VBScript. Because VBScript also uses the ADSI (Active Directory Services Interface) interface to manipulate Active Directory, the process for creating a user in VBScript is identical to the process in Windows PowerShell. A simple script for creating a user follows:
Set objOU=GetObject(“LDAP: //OU=Managers,DC=es-net,DC=co,DC=uk”)
Set objUser=objOU.Create(“user”,”CN=John Doe”)
objUser.Put “sAMAccountName”,“jdoe”
objUser.SetInfo()

In the following example we will use a VB Script to create a new OU Tempworkers, a new user Ackerman Pilar and a new Security group temp-users.

Launch Windows PowerShell, at the prompt type the command:
Cscript.exe create.vbs

Note Windows PowerShell opens in the Administrators profile because the script was saved to the root of this profile, no further path needs to be added. The script has completed, you should check Active Directory Users and Computers to ensure all the object have been created. Success.The new OU, User and Group have been created.

VB Script

So far we have seen scripts to add a single user and another to add a new OU, User and Group. The following script can be used to add multiple user accounts from 1-1000. This script is useful for test scenarios that require multiple user accounts.

When this script is run it will create 10 new users in the default Users container. Upon completion it will display a message 10 users created.
The script has been saved to the Administrator’s profile and called create10.vbs

Launch Windows PowerShell, at the prompt type the command:
Cscript.exe create10.vbs
Note Windows PowerShell opens in the Administrators profile because the script was saved to the root of this profile, no further path needs to be added.
Script completed. Note the 10 Users created message. 10 new user accounts in Active Directory.

VBScript vs. Windows PowerShell

VBScript has two major advantages over Windows PowerShell.

The first is that VBScript scripts can be run on all current versions of Windows using the WSH, whereas Windows PowerShell must be downloaded and installed on versions of Windows prior to Windows Server 2008 and requires .NET Framework 2.0 or greater.

The second advantage of VBScript is that it has been around for many years, so there is an extraordinary amount of experience, knowledge, and community-posted information on the Internet.

The disadvantages of Windows PowerShell are the inverse of the VBScript advantages.

The very fact that Windows PowerShell is new, means that it is a product still in development. In the current version of Windows PowerShell, there is very limited support for Active Directory administration.

Active Directory support is limited to the ADSI type adapter, which is quirky and awkward and, ultimately, relies on ADSI just as VBScript does. In future versions of Windows PowerShell, an Active Directory provider will be introduced that will make working with Active Directory objects easier.