Computer Performance, Windows 2003, Logon Scripts

Google

WebSearch Site

 Home
Subscribe to Newsletter
WSH - Home
WSH - Simple Script
WSH - Create User
WSH - Bulk Import
WSH - Create Group
WSH - Create Contact
WSH - FSO Create File
WSH - List Members
WSH - Error Messages
VBScript Home
Logon Script Home
CSVDE & LDIFDE
 LDAP Attributes

 

 More Sections
 Guy's eBooks
 Windows 2003
 Exchange 2003 (New)
 Performance Monitor

 

 Windows 2000 AD
 Exchange 2000
 SQL Server 2000
 SharePoint Portal

 

 Litmus Tests
 Registry Hacks
 Problem Solving
 On-line advice
 Free ebooks

 

Contact Guy
About Us
Online Jobs at CP
Guy's eBooks

 

 

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

 


Download your eBook:  How to create users with a VBScript- only $6.25

How to create users with a VBScriptSave hours of frustration and buy Guy's eBook.  The features include: detailed examples on how to import LDAP properties from a spreadsheet, Do...Loop Until  explained, connect to your domain with RootDSE.

You get a printer friendly version with copy enabled, and no expiry date.

 


See Also

 *


Google

WebComputerperformance.co.uk

GFi Events Manager

Guy Recommends: GFi EventsManager

Here is a solution to monitor, manage and archive thousands of events that are generated by devices across your entire network.  Get your free evaluation copy of GFI EventsManager.

 

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

Please report a broken link, or an error.