Logon Scripts

Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.


 

WSH - Creating New Users

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

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

  1. Copy the entire Script in the green box below.
  2. Paste it into notepad.exe.
  3. File (menu), Save as Guy.vbs.   Note: This is where people go wrong, remember the .vbs extension.
  4. Double click Guy.vbs
  5. 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 ToolFree Download 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.

There are also two bonus tools in the free download, and all 3 have been approved by Microsoft:

  1. Bulk-import new users into Active Directory.
  2. Seek and zap unwanted user accounts.
  3. Find inactive computers.

Download your FREE bulk import tool.


See Also

 *


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, Solarwinds have created the Free WMI Monitor so that you can actually see and understand these gems of performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

 

Home Copyright © 1999-2012 Computer Performance LTD All rights reserved

Please report a broken link, or an error.