I am looking for the best way to script the export of all computer accounts in our AD Domain to text files (no other info... just computer names)...I would like to be able to query for systems with the same naming conventions and export them to their own text file (ei: all xxxxPC1 sytems to PC1.txt, all xxxxPC2 systems to PC2.txt, etc)
monsterjta provided the following script when I originally posted in the Windows 2003 Server Forum... this script works except it is only finding XP and 2003 systems in my production AD??
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This script searches AD for computernames containing the
'string defined in strSearchFor. It creates and writes to
'a text file in the current directory.
'Courtesy of monsterjta @ Tek-Tips
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
Set oRootDSE = GetObject("LDAP://rootDSE")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
strSearchFor = "<search for string>"
strDomain = "LDAP://" & oRootDSE.get("defaultNamingContext") & ""
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from '" & strDomain & "' " _
& "Where objectClass='computer'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
''''''''''''''''''''''''''
'Create and open dest file
''''''''''''''''''''''''''
strWriteFile = WSHShell.CurrentDirectory & "\" & strSearchFor & ".txt"
Set CreateFile = oFSO.CreateTextFile(strWriteFile, True)
CreateFile.Close
Set strWriteFile = oFSO.OpenTextFile(strWriteFile, ForWriting)
'''''''''''''''
'Write to file
'''''''''''''''
Do Until objRecordSet.EOF
strComputerName = objRecordSet.Fields("Name").Value
If InStr(strComputerName, strSearchFor) Then strWriteFile.WriteLine(strComputerName)
objRecordSet.MoveNext
Loop
monsterjta provided the following script when I originally posted in the Windows 2003 Server Forum... this script works except it is only finding XP and 2003 systems in my production AD??
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This script searches AD for computernames containing the
'string defined in strSearchFor. It creates and writes to
'a text file in the current directory.
'Courtesy of monsterjta @ Tek-Tips
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
Set oRootDSE = GetObject("LDAP://rootDSE")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
strSearchFor = "<search for string>"
strDomain = "LDAP://" & oRootDSE.get("defaultNamingContext") & ""
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from '" & strDomain & "' " _
& "Where objectClass='computer'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
''''''''''''''''''''''''''
'Create and open dest file
''''''''''''''''''''''''''
strWriteFile = WSHShell.CurrentDirectory & "\" & strSearchFor & ".txt"
Set CreateFile = oFSO.CreateTextFile(strWriteFile, True)
CreateFile.Close
Set strWriteFile = oFSO.OpenTextFile(strWriteFile, ForWriting)
'''''''''''''''
'Write to file
'''''''''''''''
Do Until objRecordSet.EOF
strComputerName = objRecordSet.Fields("Name").Value
If InStr(strComputerName, strSearchFor) Then strWriteFile.WriteLine(strComputerName)
objRecordSet.MoveNext
Loop