Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: Query OU for Computer Objects saved to text file

HTVi
TV Discussion Newsgroups

Query OU for Computer Objects saved to text file
Mike 5/31/2007 4:36:02 PM
Need a script or command to run on specific OU's in AD and save the
Computer Object names to a text file.
Re: Query OU for Computer Objects saved to text file
"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> 5/31/2007 7:24:08 PM
Mike wrote:

[Quoted Text]
> Need a script or command to run on specific OU's in AD and save the
> Computer Object names to a text file.

Run any command line utility or script that outputs computer names in the OU
at a command prompt and redirect the output to a text file. A VBScript
example:
============
Option Explicit
Dim objOU, objComputer

' Bind to OU with Distinguished Name.
Set objOU = GetObject("LDAP://ou=Sales,dc=MyDomain,dc=com")

' Filter on objects of class computer.
objOU.Filter = Array("computer")

' Enumerate computer objects.
For Each objComputer In objOU
' Output Distinguished Name of computer.
Wscript.Echo objComputer.distinguishedName
Next
================
If this program is saved in the file EnumComputers.vbs, run it at a command
prompt with the command:

cscript //nologo EnumComputers.vbs > computers.txt

This creates the file computers.txt (in the current directory) with the
Distinguished Names of all computers in the specified OU. If instead you
want the NetBIOS names, replace "objComputer.distinguishedName" with
"objComputer.sAMAccountName". This will be the NetBIOS name with "$"
appended on the end.

Alternatively, you can use adfind or dsquery. Again, you would specify the
OU as the base of the search, search for objects of class computer, and
redirect the output to a text file. The syntax for adfind would be similar
to:

adfind -b ou=Sales,dc=MyDomain,dc=com -f "objectCategory=computer"
sAMAccountName

You can download adfind.exe from:

http://www.joeware.net/freetools/index.htm

Check this link for info on dsquery:

http://technet2.microsoft.com/windowsserver/en/library/46ba1426-43fd-4985-b429-cd53d3046f011033.mspx#BKMK_1

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen