Const ADS_SCOPE_SUBTREE = 2
set fs = CreateObject("Scripting.FileSystemObject")
set textstream = fs.CreateTextFile("hosts.xml", True)
Set rootDSE = GetObject("LDAP://RootDSE")
domainContainer = rootDSE.Get("defaultNamingContext")
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, distinguishedName from 'LDAP://" &
domainContainer & "' " _
& "Where objectClass='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 "distinguishedName: " &
objRecordSet.Fields("distinguishedName").Value
arrPath =
Split(objRecordSet.Fields("distinguishedName").Value, ",")
strOU = ""
for each a in arrPath
if left(a,2) = "OU" Then
strOU = "/" & right(a,len(a) - 3) & strOU
End If
Next
'Wscript.Echo "Path: " & StrOU
textstream.WriteLine objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop
textstream.close
Wscript.Echo "Finished..."
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment