Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '==========================================================================
  2. ' NAME: Dump Local Administrators Membership
  3. '
  4. ' AUTHOR: Brian Desmond,
  5. ' DATE  : 4/16/2007
  6. '==========================================================================
  7.  
  8.  
  9. Option Explicit
  10.  
  11. Const LogFile = "LocalAdmins.log"
  12. Const resultFile = "LocalAdministratorsMembership.csv"
  13. Const inputFile = "c:\scripts\workstations.txt"
  14.  
  15.  
  16. Dim fso
  17. Set fso = CreateObject("Scripting.FileSystemObject")
  18.  
  19. Dim shl
  20. Set shl = WScript.CreateObject("WScript.Shell")
  21.  
  22. Dim fil
  23. Set fil = fso.OpenTextFile(inputFile)
  24.  
  25. Dim results
  26. Set results = fso.CreateTextFile(resultFile, True)
  27.  
  28. WriteToLog "Beginning Pass of " & inputFile & " at " & Now()
  29. WScript.Echo "Beginning Pass of " & inputFile & " at " & Now()
  30. 'On Error Resume Next
  31.  
  32. Dim grp
  33. Dim line
  34. Dim exec
  35. Dim pingResults
  36. Dim member
  37.  
  38. While Not fil.AtEndOfStream
  39.     line = fil.ReadLine
  40.    
  41.     Set exec = shl.Exec("ping -n 2 -w 1000 " & line)
  42.     pingResults = LCase(exec.StdOut.ReadAll)
  43.    
  44.     If InStr(pingResults, "reply from") Then
  45.         WriteToLog line & " responded to ping"
  46.         WScript.Echo line & " responded to ping"
  47.        
  48.         'On Error Resume Next
  49.  
  50.         Set grp = GetObject("WinNT://" & line & "/Administrators")
  51.        
  52.         WScript.Echo line & ", Administrators"
  53.         results.WriteLine line & ",Administrators,"
  54.        
  55.         For Each member In grp.Members
  56.             WScript.Echo    "Administrators: " & member.Name
  57.             WriteToLog line & ": Administrators - " & member.Name
  58.             results.WriteLine ",," & member.Name
  59.         Next
  60.     Else
  61.         WriteToLog line & " did not respond to ping"
  62.         WScript.Echo line & " did not respond to ping"
  63.     End If
  64. Wend
  65.  
  66. results.Close
  67.  
  68. Sub WriteToLog(LogData)
  69.     On Error Resume Next
  70.  
  71.     Dim fil
  72.     '8 = ForAppending
  73.     Set fil = fso.OpenTextFile(LogFile, 8, True)
  74.        
  75.     fil.WriteLine(LogData) 
  76.  
  77.     fil.Close
  78.     Set fil = Nothing
  79. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement