VBscript to Pull out the Members of the local Adminstrators Group

Below VBscript helps to pull out Members of the Local Administrators Group from the given list of computer names. You need you have admin permission on the remote computer to pull out the membership details

 

Option Explicit

Dim objNetwork, objLocalGroup
Dim objTrans, strComputer, strNetBIOSDomain
Dim Result,k,v, Lusr,Dusr, Grp
Dim filesys
Dim filetxt,Servername

‘ Determine NetBIOS name of domain and local computer.
Set objNetwork = CreateObject(“Wscript.Network”)
strNetBIOSDomain = objNetwork.UserDomain
‘strComputer = objNetwork.ComputerName

Set filesys = CreateObject(“Scripting.FileSystemObject”)
set filetxt = filesys.OpenTextFile(“D:\scripts\LocalAdministrator\Servers.txt”,1)

do Until filetxt.AtEndOfStream
Servername = filetxt.Readline
Servername = trim(Servername)

strComputer = Servername
Set objNetwork = Nothing

‘ Bind to local Administrators group.
Set objLocalGroup = GetObject(“WinNT://” & strComputer  & “/Administrators,group”)

‘ Enumerate members of the local group.
result = strComputer
Lusr = “Local User :”
grp = “Domain Group :”
Dusr = “Domain USer : “

Call EnumLocalGroup(objLocalGroup,strComputer)

Loop

Sub EnumLocalGroup(ByVal objGroup,strComputer)
    ‘ Subroutine to enumerate members of local group.
    ‘ The variable strComputer has global scope.

    Dim objMember

    ‘ Enumerate direct members of group.
    For Each objMember In objGroup.Members

 If (LCase(objMember.Class) = “group”) Then
 K = objMember.AdsPath
 V = split(K,”/”)
 grp = grp & V(2) & “/” & v(3) & ” : ”
 Else
        K = objMember.AdsPath
 V = split(K,”/”)
 if Ubound(v) = 3 Then
 Dusr = Dusr  & V(2) & “/” & v(3) & ” : ”
 ElseIF Ubound(v) = 4 Then
 Lusr = Lusr & V(3) & “/” & v(4)  & ” : ”
 ‘wscript.echo objMember.AdsPath
 End If
 End If
    Next
 wscript.echo Ucase(strComputer) & “,” & Ucase(Lusr) &”,” & Ucase(Dusr) &”,” & Ucase(grp)
End Sub

 

Copy of the script can be found in the below mentioned Link

http://powershell.com/cs/members/smtpport25.wordpress/files/AdminMembers.txt.aspx

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