How to Create a Computer Account with VBScript
Tutorial for Creating a Computer Account with VBScript
Here are examples of VBScripts that you can use to create computer accounts. Compared with user accounts, computer accounts are relatively easy to script because they need fewer properties. The only compulsory attributes are sAMAccountName and userAccountControl, there is no need to script sn (surname) or password. I designed these scripts in a Windows 2003 Active Directory domain, but they should work equally well in Windows 2000.
Topics for Creating a Computer Account with VBScript
Our goal is to create computer accounts. The first mission is to create new computers in Active Directory's Computers container and our second mission is to create more computers, but in a named OU.
My best work is often getting people started. Therefore here on this page, we concentrate on the essential VBScript commands, namely, to bind with Active Directory and create the Computer object. Once we have mastered the basics, I have a separate page to tackle bulk import by reading computer names from a spreadsheet.
Recommended: that you logon as administrator, preferably at a domain controller. If you are a long way from the server, Remote Desktop would be a suitable alternative. If that is not possible, you could get these scripts to work from an XP machine as a non-administrator. However, why introduce extra complications? Especially at the beginning, you want easy success, with fewest obstacles.
Instructions for Creating a Computer Account in Active Directory
Script to Create a Computer in Your Active Directory
' Computer .vbs
Note 1: The header section (first 10 lines) explains the purpose of the script and declares the variables.
Note 2: The simple, but clever command which allows the script to work with any domain is: GetObject("LDAP://rootDSE"). Crucial, this statement binds WSH / VBScript to Active directory. The next line puts the focus on the Computers container, as that is where the strComputer will be born.
Note 3: .Create is a method to build an object, observer how we use "Computer" not "User" or "OU".
Note 4: sAMAccountName controls the ComputerName. Computer accounts need a dollar sign appended to their name, see where I add: & "$".
Note 4: The correct userAccountControl value for a computer is 4096. (If this were a user account then the value would be 512 or 514.)
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)
That you already have an OU to hold the new computers, my OU is called Accounts
Instructions for Creating a Computer Account in a Named OU
' ComputerOU .vbs
VBScript Tutorial - Learning Points
Note 1: The key difference between the two scripts is: strOU = "OU=Accounts ,". Trace how VBScript applies this variable to set the Organizational Unit.
Note 2: This command looks easy to script: GetObject("LDAP://" & strOU & _. However it took me ages to get the comma, the speech marks and the ampersands (&) just right. O.K there is no comma here; because I ended up putting the comma at the end of strOU.
Note 3: objShell.run is just me having a little fun. What this command does is open the Active Directory Users and Computers MMC ready for you to inspect the new computer account.
In addition to creating the actual computer account, take the time to learn the VBScript object (Computer), method (Create) and value (strComputer) technique. Using these example scripts, you can soon create a new computer account either in an OU or in the Computers container.
If you like this page then please share it with your friends
See more VBScript examples: