List Servers in WMI
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.FileExists("c:listcomputers.txt") Then
set f = fso.GetFile("c:listcomputers.txt")
f.delete
End If
set l = createobject("WbemScripting.SWbemLocator")
Set f = fso.CreatetextFile("c:listcomputers.txt", ForAppending, True)
'This constructor is (ServerName, Namespace, UserId, password)
Set m = l.ConnectServer("DC1.bgeek.com", "root/directory/LDAP", "administrator",
"password")
For Each Item In m.ExecQuery("SELECT * FROM ds_computer")
f.Write item.ds_cn & VbCrLf
Next
set l = nothing
set f = nothing
set m = nothing
set fso = nothing
msgbox "Done!"
|