Introduction – Creating New Users with WSH
In Active Directory, when you need to create one or two users, Active Directory User’s and Computers is the classic tool. However, there may be times when you prefer to use WSH (Windows Scripting Host) to generate new user accounts.
WSH Topics
- Creating a New OU
- Creating a New user
- Setting the password
- Disabling the account
- Instructions
- Error Messages
♦
Creating a New OU
Before we consider the user, first we need to build an OU (organizational unit) to house the users. An advantage of having a special OU for learning about scripting is that the accounts you produce’ do not get mixed up with existing accounts in the Users container. So we will call upon WSH to generate a new OU. In my example I have called the OU GuyDemo, change that name if you wish. In WSH, the following line takes care of creating the OU:
Set oOU=oDomain.Create("organizationalUnit", "ou=GuyDemo")
Creating a New User
In my example the user will be called Guy Thomas, feel free to alter the oUser if you prefer a different name. These two lines take care of the user:
Set oUser = oOU.Create("User", "cn=Guy Thomas")
oUser.Put "sAMAccountName", "GuyThomas"
See more on Creating Users here
Setting the password
A benefit of using WSH with VBScripts is that you can set a password. This is a big advantage over CSVDE which can only create users with blank passwords. This line takes care of the password:
oUser.SetPassword "dem0Gu1do"
Disabling the account
If you see a red X next to the user, that means the account is disabled. Change this statement from True to FALSE if you want the accounts enabled and ready to logon.
oUser.AccountDisabled = True
Instructions
- Copy the entire Script in the green box below.
- Paste it into notepad.exe.
- File (menu), Save as Guy.vbs. Note: This is where people go wrong, remember the .vbs extension.
- Double click Guy.vbs
- Go to Active Directory Users and Computers, Press F5, observe the GuyDemo OU.
‘Script to Create a new user account in the GuyDemo OU
‘Script created by Guy Thomas
‘Feel free to adapt names
Set oRoot = GetObject("LDAP://rootDSE")
Set oDomain = GetObject("LDAP://" & oRoot.Get("defaultNamingContext"))
Set oOU=oDomain.Create("organizationalUnit", "ou=GuyDemo")
oOU.Put "Description", "Guy’s Script Pure OU"
oOU.SetInfo
Set oUser = oOU.Create("User", "cn=Guy Thomas")
oUser.Put "sAMAccountName", "GuyThomas"
oUser.Put "Description", "Guy’s Script made this User"
oUser.SetInfo
oUser.SetPassword "dem0Gu1do"
oUser.AccountDisabled = True
oUser.SetInfo
Wscript.Echo "Success, Check Active Directory Users and Computers – Remember F5"
See more on Creating Users here
Guy Recommends: SolarWinds’ Free 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)
◦