Also tests the connectivity, it gets computers from AD object type “computer”
and it prints out a nice report.

```'Remotely Get Local Admins Users inside Administrators group, for Workstations
'Author: Felipe Ferreira fel[a)gmail.com
'Date 18/05/09
'Version 1.0
'todo(next version):
'Get LastLoginTime, get account stauts: disable or enable
'remove server from AD if not ping
Const ForAppending = 8
Dim strPingit,strList
Dim strcomputer
Dim strLocalGroup2 : strLocalGroup2 = "Administrators"   'english
Dim verbose : verbose = 1                      'debuging =1, silent =0
Dim oFSO : Set oFSO = CreateObject("Scripting.FilesyStemObject")
Dim Outputfile : outputfile = "list_pcs.txt"
'Get list of all computer objects from AD
Set objOU = GetObject("LDAP://CN=Computers, DC=YOURDOMAIN, DC=es" )         '!!EDIT HERE!!
objOU.Filter = Array(" Computer" )
Set ofile = oFso.OpenTextFile(Outputfile, ForAppending, TRUE)
oFile.Writeline "#################START##################"
oFile.Writeline "Script: started in " & Date & " at " & Time & VbCrLf
For Each objComputer in objOU
Wscript.StdOut.Write(".")
if instr(lcase(objComputer.CN),"bcn") then                         ' EDIT IF YOU WANT JUST CERTAIN COMPUTERS
strComputer = objComputer.CN
GetStatus strcomputer
pt " =================================================="
if strPingit = true then
pt vbcrlf & "--> " & strComputer & " "& IPAddress & ", UP"
pt " =================================================="
'build list
'Remotely get the local Administrators group members
err.clear
on error resume next
Set objGroup = GetObject("WinNT://" & strComputer & "/" & strLocalGroup)
if err.level <> 0 then
pt "Maybe OS is in English,testing..."
Set objGroup = GetObject("WinNT://" & strComputer & "/" & strLocalGroup2)
end if
For Each objUser In objGroup.Members
pt vbTab & objUser.Name
oFile.Writeline vbTab & objUser.Name
next ' next user in Admins group
else
'List PCs that are in AD but have no ping. bad entries, or connectivity problems!
pt strComputer & " "& IPAddress & ", DOWN"
strList = strList & "," & strComputer &"  "& IPAddress
end if
end if
IP = 0
next 'next computer
pt "BCN Computers in AD but no Ping: " & vbcrlf & strList
oFile.WriteLine "Computers in AD but no Ping: " & vbcrlf & strList
oFile.Writeline "#################END##################"
oFile.Writeline "Script: finished in " & Date & " at " & Time & VbCrLf
wscript.quit(0)
Function GetStatus(strComputer)
'Check if computer is UP
On Error Resume Next
Dim wmiQuery, objWMIService, objPing, objStatus, intReply, i
' Define WMI query to ping
wmiQuery = "Select * From Win32_PingStatus Where " & _
"Address = '" & strComputer & "'"
' Make WMI connection to local machine
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
' Execute Query
For i = 1 To 4
Set objPing = objWMIService.ExecQuery(wmiQuery)
' Retrieve the status code of each ping request
For Each objStatus In objPing
Select Case objStatus.StatusCode
Case 0
End Select
Next
Next
Set objPing = Nothing
Set objWMIService = Nothing
' Determine the image color depending on the number of pings successfully received
Select Case True
strPingit = false
strPingit = true
Case Else
strPingit = true
End Select
End Function
Function GetIP(strcomputer)
Dim ws : Set ws = CreateObject("WScript.Shell")
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim TmpFile : TmpFile = fso.GetSpecialFolder(2) & "ip.txt"
Dim ThisLine, IP,p1,p2,p3
p1 = 0
p2 = 0
p3 = 0
' pt "cmd.exe /c ping -a -n 1 -w 900 " & strcomputer & " | find "&chr(34)& "["&chr(34)& " > "  & TmpFile
ws.run ("cmd.exe /c ping -a -n 1 -w 900 " & strcomputer & " | find "&chr(34)& "["&chr(34)& ">" & TmpFile),0,true
wscript.sleep 1200
Dim ifile : Set ifile = fso.OpenTextFile(TmpFile)
Do until ifile.AtEndOfLine
'              pt "Parse Ping Debug: " & ThisLine
If InStr(ThisLine, strcomputer) then
p1 = InStr(ThisLine,"[")
p2 = InStr(ThisLine,"]")
p3 =  (p2 - p1) + 1
ThisLine=right(ThisLine,p1)
IP=left(ThisLine,p3)
'pt "ip: " & IP
end if
loop
ifile.close
if (IP <> "") or (IP <> "0") then
GetIP = IP
else
pt "Error getting remote IP for " & strComputer
end if
wscript.sleep 300
fso.DeleteFile TmpFile
Set fso = Nothing
Set ws = Nothing
End Function
function pt(txt)
if verbose=1 then
wscript.echo txt
end if
end function```
Tags: , , , , , , , , ,