How to get local administration on the Server with vbs script

Posted: August 15, 2012 in Tips & Trick

Below are scritp to get local administrator on the server. If your company request to auditing who is local administration on a server, you can use the script. You can customize the script appropiate your path where you place the list server and the result file.

You can edit three line script :

Const LogFile = “LocalAdmins.log” –> log file will be automatically created when you running the script
Const resultFile = “LocalAdministratorsMembership.csv” –> result file
Const inputFile = “D:\My Job\office\customer\Script\workstations.txt” –> Paht List server

Save as script with *.vbs format

Option Explicit
Const LogFile = “LocalAdmins.log”
Const resultFile = “LocalAdministratorsMembership.csv”
Const inputFile = “D:\My Job\Kairos\XL\Script\workstations.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)
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
WriteToLog line & “: Administrators – ” & member.Name
results.WriteLine “,,” & member.Name
Next
Else
WriteToLog line & ” did not respond to ping”
End If
Wend
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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s