Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - Active Directory and Computers
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Active Directory and Computers
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-01-10

    Table of Contents:
  • Active Directory and Computers
  • Creating a Computer
  • Creating a Computer for a Specific User or Group
  • Joining a Computer to a Domain

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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

    1. Open the ADUC 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. 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.
    5. 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.
    6. 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

    More Windows Scripting Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Active Directory Cookbook, Second...
     

    Buy this book now. 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.

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek