Skip to main content

VB Script to List Local Administrators Membership

VB Script to List Local Administrators Membership

Script Credit : Brian Desmond

'==========================================================================
' NAME: Dump Local Administrators Membership
'
' AUTHOR: Brian Desmond,
' DATE  : 4/16/2007
'==========================================================================


Option Explicit

Const LogFile = "LocalAdmins.log"
Const resultFile = "LocalAdministratorsMembership.csv"
Const inputFile = "c:\scripts\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)

WriteToLog "Beginning Pass of " & inputFile & " at " & Now()
'WScript.Echo "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)
    
    'pingResults ="reply from"
     If InStr(pingResults, "reply from") Then
         WriteToLog line & " responded to ping"
         'WScript.Echo line & " responded to ping"
        
         On Error Resume Next

        Set grp = GetObject("WinNT://" & line & "/Administrators")
       
        'WScript.Echo line & ", Administrators"
        results.WriteLine line & ",Administrators,"
       
        For Each member In grp.Members
            'WScript.Echo     "Administrators: " & member.Name
            WriteToLog line & ": Administrators - " & member.Name
            results.WriteLine ",," & member.Name
        Next
    Else
        WriteToLog line & " did not respond to ping"
        'WScript.Echo line & " did not respond to ping"
    End If
Wend

results.Close
WScript.Echo "Operation Finished"

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

Comments

Popular posts from this blog

Changing Default Port of WSUS Server from 8530 to 80?

Problem : How to change Default Port of WSUS Server from 8530 to 80?Environment : Windows Server 2008 R2 with WSUS 3.0 SP2Solution :1) Go to Start -> RUN -> inetmgr

2) Go to "WSUSAdministration" Site

3) Under "Edit Site", click on "Bindings"

3) Change the port from 8530 to 80, and click OK

4) Open Registry Editor with Start -> RUN -> regedit

5) Goto HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Update Services\Server\Setup

6) Change "Port Number" Value to "80"

7) Goto Command prompt and type following command
cscript "WSUS Installation Location\Update Services\setup\installselfupdateonport80.vbs
e.g.
"cscript "c:\Program Files\Update Services\setup\installselfupdateonport80.vbs"
C:\Windows\system32>cscript "c:\Program Files\Update Services\setup\installselfupdateonport80.vbs"

Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
SetupSelfupdateTree: Finding th…