Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list computer accounts

Status
Not open for further replies.
Jul 27, 2004
397
0
0
US
Can someone give me a script to query AD and list all computer accounts and output to a text file for use later?

thanks,

Network Admin
A+, Network+, MCSA 2000, MCSE 2000
 
Have you searched this forum and/or the web? This topic has been covered ad nauseum.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
'==========================================================================
'
' NAME: <EnumerateDomainComputers.vbs>
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: ' DATE : 5/20/2004
'
' COMMENT: generates a list of domain computers
' MODIFICATIONS: Added support to automatically find the Domain NetBIOS Name
'==========================================================================

Dim objIADsContainer ' ActiveDs.IADsDomain - ' Container object
Dim objIADsComputer ' ActiveDs.IADsComputer
Dim Partition, Partitions
Set Partitions = GetObject("LDAP://CN=Partitions,CN=Configuration," & _
GetObject("LDAP://RootDSE").Get("DefaultNamingContext"))
On Error Resume Next
For Each Partition In Partitions
strDomain = Partition.Get("nETBIOSName")
If Err.Number = 0 then Exit For
Next
Set Partitions = Nothing


' connect to the computer.
Set objIADsContainer = GetObject("WinNT://" & strDomain)

' set the filter to retrieve only objects of class Computer
objIADsContainer.Filter = Array("Computer")


For Each objIADsComputer In objIADsContainer
report = report & objIADsComputer.Name & vbCrLf
Next


Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile ("wslist.txt", ForWriting)
ts.write report


Set fso = Nothing
Set objIADsComputer = Nothing
Set objIADsContainer = Nothing


MsgBox "Done"

Marty
Network Admin
Hilliard Schools
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top