I had a need for checking all servers in a list to which my AD Group has access. The list was around 3000 Windows servers and there is no way I could do it manually. So I did a Google search and found a nice script written by Brian Desmond at this link which shows all the users who are added as Local Administrators.
_briandesmond.com/blog/script-to-collect-local-administrators-membership-from-list-of-machines/
Thanks Brian.
--
I did a small modification so that it just prints out the names of the servers to which my AD group has access and also print out server names which I am unable to ping. The script is pretty raw and takes lot of time to check each server, but this is the only one I have for now.
->Save the below script as localadminFile.vbs
->create localadminfiles.bat with the below line
wscript localadminFile.vbs
-> place localadminfiles.bat in scheduler and let it run. Keep checking for the completed.
-> also you will find 'wscript' in taskmanager if you want to kill of the running script.
Modify it according to your need.
**************************
Option Explicit
Const LogFile = "G:\temp\LogFile.log"
Const resultFile = "G:\temp\LocalAdmin.csv"
Const inputFile = "G:\temp\serverList.txt"
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim shl
Set shl = WScript.CreateObject("WScript.Shell")
Dim fil
Set fil = fso.OpenTextFile(inputFile)
Dim results
Set results = fso.CreateTextFile(resultFile, True)
WriteToLog "Beginning Pass of " & inputFile & " at " & Now()
'On Error Resume Next
Dim grp
Dim line
Dim exec
Dim pingResults
Dim member
While Not fil.AtEndOfStream
line = fil.ReadLine
Set exec = shl.Exec("ping -n 2 -w 1000 " & line)
pingResults = LCase(exec.StdOut.ReadAll)
If InStr(pingResults, "reply from") Then
'WriteToLog line & " responded to ping"
On Error Resume Next
Set grp = GetObject("WinNT://" & line & "/Administrators")
'results.WriteLine line & ",Administrators,"
For Each member In grp.Members
If member.name = "AdminGroup AD" Then
WriteToLog line & "--> Server is supported by Team"
results.WriteLine ",," & member.Name
End If
Next
Else
WriteToLog line & "did not respond to ping"
End If
Wend
WriteToLog line & "-->Script END - COMPLETED.."
results.Close
Sub WriteToLog(LogData)
On Error Resume Next
Dim fil
'8 = ForAppending
Set fil = fso.OpenTextFile(LogFile, 8, True)
fil.WriteLine(LogData)
fil.Close
Set fil = Nothing
End Sub
**************************
No comments:
Post a Comment