Skip to Content
Active Directory Cookbook
book

Active Directory Cookbook

by Robbie Allen
September 2003
Intermediate to advanced
624 pages
15h 49m
English
O'Reilly Media, Inc.
Content preview from Active Directory Cookbook

8.1. Creating a Computer

Problem

You want to create a computer account.

Solution

Using a graphical user interface

  1. Open the Active Directory Users and Computers snap-in.

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

  3. In the left pane, browse to the parent container for the computer, right-click on it, and select New Computer.

  4. Enter the name of the computer and click OK.

Using a command-line interface

> dsadd computer "<ComputerDN>" -desc "<Description>"

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

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 a user object. I set the description attribute in the CLI and API solutions, but it is not a mandatory attribute. The only mandatory attribute is sAMAccountName ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Active Directory Administration Cookbook

Active Directory Administration Cookbook

Sander Berkouwer
Active Directory Cookbook, 3rd Edition

Active Directory Cookbook, 3rd Edition

Laura E. Hunter, Robbie Allen
Active Directory Cookbook, 4th Edition

Active Directory Cookbook, 4th Edition

Brian Svidergol, Robbie Allen

Publisher Resources

ISBN: 0596004648Supplemental ContentCatalog PageErrata