VBScript to create computer accounts
VBScript Create Computer Accounts
What the script does is to connect to Active Directory, then create a XPSimple in the ‘Computer’ container.
GetObject connects to ("LDAP://rootDSE") that is why the script will work on any domain. Then it extracts the domain name ("defaultNamingContext") and builds the path to the "Computer" container.
‘ VBScript to create one computer
‘ Guy Thomas January 2003
strComputer = "XPSimple"
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Computers," & _
Set objLeaf = objContainer.Create("Computer", "cn=" & strComputer)
objLeaf.Put "sAMAccountName", strComputer & "$"
objLeaf.Put "userAccountControl", 4096
- UserAccountControl 512 is Enabled, 514 is disabled.
- strComputer is a string variable for the name of the computer. Feel free to change strComputer = "XPSimple" to a different computer name.
- Even though this is a computer object, it still needs the sAMAccountName.
And then the script developed into this monster!
Goals for the ‘Monster Script’
I decided I wanted the script to create machine accounts, not in the ‘Computer’ container, but an OU of my choice.
One computer was not enough, I wanted to make 10 (or more).
‘ Created by Guy Thomas January 2003
‘ Script to create ten computers in strOU
Dim objLeaf, objRootDSE, objDomain, objOU, objComputer
Dim strXPStation, strOU, strSam, strDomain
strXPStation = "XPMachine"
strOU = "Accounts"
strSam = "sAMAccountName"
‘ Get Domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")
‘ Create OU = strOU
Set objDomain = GetObject("LDAP://" &strDomain )
Set objOU = objDomain.Create("organizationalUnit", "ou=" & strOU)
‘ Create Computers
For intComputerNum = 1 To 10
Set objLeaf = objOU.Create("Computer", "cn=" & StrXPStation & intComputerNum)
objLeaf.Put strSam, strXPStation & intComputerNum & "$"
‘ 512 means Enable the Account
intComputerNum = intComputerNum -1
WScript.Echo intComputerNum & " Machines created in " & strOU & " OU"
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)
- This script creates an OU that you specify with the strOU. So feel free to alter strOU = "Accounts" to another name.
- The ‘For …… Next’ loop is responsible for making multiple machines, each with a different digit at the end of the XPMachine name.