SunQuest
 
       Windows Scripting
  Home arrow Windows Scripting arrow Page 5 - Modifying Computer Objects with Active Dir...
Moblin
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 
Moblin 
JMSL Numerical Library 
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 / 4
    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

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Modifying Computer Objects with Active Directory - Listing All the Computer Accounts in a Domain


    (Page 5 of 6 )

    Problem

    You want to obtain a list of all computer accounts in an Active Directory domain.

    Solution

    Using a graphical user interface

    1. Open the Active Directory Users and Computers MMC snap-in.
    2. Right-click on the domain node and select Find.
    3. In the Find drop-down box, select Computers and click Find Now.

      All computer objects in the domain will be displayed in the Search Results window.

    Using a command-line interface

      > adfind –default –f (objectCategory=computer)

    Using VBScript

      ' The following script will enumerate all computer accounts
      ' within an Active Directory domain.

      Const ADS_SCOPE_SUBTREE = 2
      strDomain = "<DomainDN>"

      Set objConnection = CreateObject("ADODB.Connection")
      Set objCommand = CreateObject("ADODB.Command")
      objConnection.Provider = "ADsDSOObject"
      objConnection.Open "Active Directory Provider"

      Set objCOmmand.ActiveConnection = objConnection
      objCommand.CommandText = _
          "Select Name, Location from 'LDAP://" & strDomain & "' " _
            
    & "Where objectCategory='computer'"
      objCommand.Properties("Page Size") = 1000
      objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
      Set objRecordSet = objCommand.Execute
      objRecordSet.MoveFirst

      Do Until objRecordSet.EOF
         
    Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
         
    Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
         
    objRecordSet.MoveNext
      Loop

    Discussion

    Using VBScript

    To obtain a list of domain controllers, rather than just computer objects, you should query the Configuration NC rather than the domain NC, and replace "where objectCategory=computer" with "where objectCategory=ntDSDSA".

    See Also

    MSDN: Object Class and Object Category [Active Directory] and MSDN: Object-Class Attribute [AD-Schema]

    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

    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - 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





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