Recipe 16.17. Creating a Computer AccountProblemYou want to create a computer account. SolutionUsing a graphical user interface
Using a command-line interfaceUse the following command to create a computer account in Active Directory: > dsadd computer "<ComputerDN>" -desc "<Description>" Using VBScript' This code creates a computer account in Active Directory. ' ------ 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 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" DiscussionCreating a computer account in Active Directory is not much different from creating a user account. In the CLI and API solutions, I set the description attribute, but it is not mandatory. The only mandatory attribute for computer accounts is sAMAccountName, which should be set to the name of the computer with $ appended (e.g., joe-wxp$). These solutions simply create a computer account. You'll still need to join a computer with the same name as the computer account to a domain as I describe in Recipe 16.18. See AlsoMS KB 222525 (Automating the Creation of Computer Accounts), MS KB 283771 (HOW TO: Pre-stage 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 |