Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - Modifying Computer Objects with Active Dir...
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

Modifying Computer Objects with Active Directory
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2008-01-31

    Table of Contents:
  • Modifying Computer Objects with Active Directory
  • Finding Computers with a Particular OS
  • Binding to the Default Container for Computers
  • Changing the Default Container for Computers
  • Listing All the Computer Accounts in a Domain
  • Identifying a Computer Role

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Modifying Computer Objects with Active Directory - Binding to the Default Container for Computers


    (Page 3 of 6 )

    This recipe requires the Windows Server 2003 domain functional level.

    Problem

    You want to bind to the default container that new computer objects are created in.

    Solution

    Using a graphical user interface

    1. Open LDP.
    2. From the menu, select Connection -> Connect.
    3. For Server, enter the name of a domain controller (or leave blank to do a serverless bind).
    4. For Port, enter 389.
    5. Click OK.
    6. From the menu, select Connection -> Bind.
    7. Enter credentials of a domain user.
    8. Click OK.
    9. From the menu, select View -> Tree.
    10. For the DN, enter: 

       <WKGUID=aa312825768811d1aded00c04fd8d5cd,
      <DomainDN>> 

      where <DomainDN> is the distinguished name of a domain .
    11. Click OK.
    12. In the lefthand menu, you can now browse the default computers container for the domain.

    Using a command-line interface

    With tools like netdom, if there is an option to specify only the name of the computer and not its DN or parent container, the computer object will be created in the default Computers container by default. You can use the redircmp utility to change this default location, as we will discuss in Recipe 8.15.

    Using VBScript

      ' This code illustrates how to bind to the default computers container.
      ' ------ SCRIPT CONFIGURATION ------
      strDomain = "<DomainDNSName>"  ' e.g. apac.rallencorp.com
      ' ------ END CONFIGURATION ---------

      ' Computer GUID as defined in ntdsapi.h
      Const ADS_GUID_COMPUTRS_CONTAINER = "aa312825768811d1aded00c04fd8d5cd"

      set objRootDSE = GetObject("LDAP://" & strDomain & "/RootDSE")
     
    set objCompContainer = GetObject("LDAP://<WKGUID=" & _ 
                     ADS_GUID_COMPUTRS_CONTAINER & "," & _
                     objRootDSE.Get("defaultNamingContext") & ">" )

      WScript.Echo objCompContainer.Get("distinguishedName")

    Discussion

    In much the same way that the TCP/IP protocol defines a list of well-known ports that are commonly used by industry applications (TCP 20 and 21 for FTP, TCP port 80 for HTTP, etc.), Active Directory defines Well-Known GUIDs that map to container objects that are present in every AD installation. The Domain NC defines the following WKGUIDs:

    • Users
    • Computers
    • System
    • Domain Controllers
    • Infrastructure
    • Deleted Objects
    • Lost and Found

    The Configuration NC also defines its ownDeleted Objects WKGUID.

    For example, the default computers container has the following WKGUID:

      aa312825768811d1aded00c04fd8d5cd

    You can use the GUID to bind to the default computers container in the domain using the following ADsPath:

     LDAP://<WKGUID=aa312825768811d1aded00c04fd8d5cd, dc=apac,dc=rallencorp,dc=com>

    The list of well-known objects for a domain is contained in thewellKnownObjectsattribute of thedomainDNS object for the domain. ThewellKnownObjectsattribute is multivalued with DNWithBinary syntax. The following is an example of what that attribute looks like for the rallencorp.com domain:

      B:32:AA312825768811D1ADED00C04FD8D5CD:CN= Computers,DC=rallencorp,DC=com; 
      B:32:F4BE92A4C777485E878E9421D53087DB:CN= Microsoft,CN=Program
      Data,DC=rallencorp,DC=com; 
      B:32:09460C08AE1E4A4EA0F64AEE7DAA1E5A:CN= Program Data,DC=rallencorp,DC=com;
      B:32:22B70C67D56E4EFB91E9300FCA3DC1AA:
      CN=ForeignSecurityPrincipals,DC= rallencorp,DC=com;
      B:32:18E2EA80684F11D2B9AA00C04F79F805:CN= Deleted Objects,DC=rallencorp,DC=com;
      B:32:2FBAC1870ADE11D297C400C04FD8D5CD:CN= Infrastructure,DC=rallencorp,DC=com;
      B:32:AB8153B7768811D1ADED00C04FD8D5CD:CN= LostAndFound,DC=rallencorp,DC=com;
      B:32:AB1D30F3768811D1ADED00C04FD8D5CD:CN= System,DC=rallencorp,DC=com;
      B:32:A361B2FFFFD211D1AA4B00C04FD7D83A:OU= Domain Controllers,DC=rallencorp,DC=com;
      B:32:A9D1CA15768811D1ADED00C04FD8D5CD:CN= Users,DC=rallencorp,DC=com;

    Each value has the format of:

      B:NumberofBytes:GUID:DistinguishedName

    As you can see, the GUID for the first value is the same as the one we used in the ADsPath above to bind to the default computers container.

    See Also

    Recipe 8.15 for changing the default computers container, and MSDN: Binding to Well-Known Objects Using WKGUID

    More Windows Scripting Articles
    More By O'Reilly Media


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

    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

    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory
    - Moving and Renaming Computers with Active Di...
    - Working with System Processes in WSH





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway