Computer Performance, Windows 2003, Exchange 2003, Logon Scripts

Guy recommends:
Free config generator

Solarwinds Config Generator

This CG will put you in charge of controlling changes to network routers and other SNMP devices.

Download your free Config Generator


 

VBScript - Simple script to create computers

VBScript to create computer accounts

Note1 : I have a new script to create a computer.

Note 2: I have a VBScript to create a computer from an Excel Spreadsheet

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," & _
objRootDSE.Get("defaultNamingContext"))

Set objLeaf = objContainer.Create("Computer", "cn=" & strComputer)
objLeaf.Put "sAMAccountName", strComputer & "$"
objLeaf.Put "userAccountControl", 4096
objLeaf.SetInfo

 

 

Learning Points

  • 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).

 

'

VBScript
' Created by Guy Thomas January 2003
' Script to create ten computers in strOU

Option Explicit
Dim objLeaf, objRootDSE, objDomain, objOU, objComputer
Dim strXPStation, strOU, strSam, strDomain
Dim intComputerNum

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)
objOU.SetInfo


' 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
objLeaf.Put "userAccountControl",512
objLeaf.SetInfo

objLeaf.SetInfo
Next
intComputerNum = intComputerNum -1
WScript.Echo intComputerNum & " Machines created in " & strOU & " OU"
WScript.Quit

 


Note1 : I have a new script to create a computer.

 

Note 2: I have a VBScript to create a computer from an Excel Spreadsheet


Learning Points

  • 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.

 


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

Guy Recommends: SolarWinds Engineer's Toolset v10Engineer's Toolset v10

The Engineer's Toolset v10 provides a comprehensive console of utilities for troubleshooting computer problems.

There are so many good gadgets, it's like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, discovery, diagnostic, and Cisco tools.  Download your copy of the Engineer's Toolset v 10

 

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

Please report a broken link, or an error.