Active Directory and Computers - Creating a Computer
(Page 2 of 4 )
Problem
You want to create a computer account.
Solution
Using a graphical user interface
Open the ADUC snap-in.
If you need to change domains, right-click on Active Directory Users and Computers in the left pane, select “Connect to Domain,” enter the domain name, and click OK.
In the left pane, browse to the parent container for the computer, right-click on it, and select New -> Computer.
Enter the name of the computer. If necessary, place a checkmark next to “Assign this computer as a pre-Windows 2000 computer” or “Assign this computer as a backup domain controller.” Click Next to continue.
If you will be using this computer account as part of an RIS deployment, place a checkmark next to “This is a managed computer” and enter the GUID that it should use, and then click Next. Otherwise, just click Next to continue.
Click Finish.
Using a command-line interface You can create a computer object using either the built-in DSAdd utility or AdMod. To create an account using DSAdd, use the following syntax:
> dsadd computer "<ComputerDN>" -desc "<Description>"
To create a computer account using AdMod, enter the following:
> admod -b "<ComputerDN>" objectclass::computer
sAMAccountName::<ComputerName>$ userAccountControl::4096
description::"<Description>" -add
Using VBScript ' This code creates a computer object.
' ------ SCRIPT CONFIGURATION -----
strBase = "<ParentComputerDN>" ' e.g. cn=Computers,dc=rallencorp,dc=com
strComp = "<ComputerName>" ' e.g.
joe-xp
strDescr = "<Description>" ' e.g. Joe's Windows XP workstation
' ------ END CONFIGURATION --------
' ADS_USER_FLAG_ENUM
Const ADS_UF_WORKSTATION_TRUST_ACCOUNT = &h1000 ' 4096
set objCont = GetObject("LDAP://" & strBase)
set objComp = objCont.Create("computer", "cn=" & strComp)
objComp.Put "sAMAccountName", strComp & "$"
objComp.Put "description", strDesc
objComp.Put "userAccountControl", ADS_UF_WORKSTATION_TRUST_ACCOUNT
objComp.SetInfo
Wscript.Echo "Computer account for " & strComp & " created"
Discussion Creating a computer object in Active Directory is not much different from creating auser object. We set thedescriptionattribute in the CLI and API solutions, but it is not a mandatory attribute. The only mandatory attribute issAMAccountName, which should be set to the name of the computer with$appended. Also note that these solutions simply create acomputerobject. This does not mean any user can join a computer to the domain with that computer account. For more information on creating acomputer object and allowing a specific user or group to join the computer to the domain, see Recipe 8.2.
See Also
Recipe 8.2 for creating a computer for a user, MS KB 222525 (Automating the Creation of Computer Accounts), MS KB 283771 (How to Prestage Windows 2000 Computers in Active Directory), MS KB 315273 (Automating the Creation of Computer Accounts), MS KB 320187 (How to Manage Computer Accounts in Active Directory in Windows 2000), and MSDN: ADS_USER_FLAG_ENUM
Next: Creating a Computer for a Specific User or Group >>
More Windows Scripting Articles
More By O'Reilly Media
|
This article is excerpted from chapter eight of the Active Directory Cookbook, Second Edition, written by Robbie Allen and Laura E. Hunter (O'Reilly; ISBN: 059610202X). Check it out today at your favorite bookstore. Buy this book now.
|
|