Find out the members of the local administrator group remotely.
Want to find out who is in the admin group on a box in your domain and don't have privileges to logon?
So I've found myself in a spot where I need to find out who owns a box and I don't have administrators privileges to logon and find out whose in the admin group myself. In these instances it might be difficult to find out who you should contact to resolve an issue.
Just today, someone contacted us asking who owns the DHCP service on ServerX. Well ServerX is not something I have access to, so the easiest way is to look at the administrators group on the machine and contact them.
I mean, how often do you own a server and not throw yourself in the admin group? Here's a simple script that will enumerate the members of the administrator group remotely. You can obviously adjust the string or strGroup to point to whatever group your interested in. Just supply the computer your after as the first and only argument and away you go!
'Just copy this into notepad and save as whatever.vbs
set objArgs = WScript.Arguments 'This tells us that we want to acept arugments for our script
strGroup = "Administrators" 'We're setting strGroup to be equal to Administrators
strComputer = objArgs(0)'Here we are saying that the first argument that is passed to our script by the user should be assigned to strComputer
WScript.Echo "Computer: " & strComputer 'Now we're just echoing out the computer name
Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ", group")
WScript.Echo " " & strGroup & " group members:"
For Each objMember In objGroup.Members
WScript.Echo vbCrLf & " Name: " & objMember.Name 'Echoing out each member name and then a carriage return.
Next
SAMPLE OUTPUT:
C:\Users\bradrutk\Desktop>test.vbs ServerX
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
Computer: ServerX
Administrators group members:
Name: Domain Admins
Name: users_group
Name: Bradrutk
Name: MattS
Comments
Anonymous
January 01, 2003
The comment has been removedAnonymous
January 01, 2003
Information that would have been useful to me yesterday! (Wedding Singer)Anonymous
July 16, 2013
This is great, thanks for making it available!Anonymous
January 16, 2014
Under an amendment if administrators want to add them to excel:Set objExcel = CreateObject("Excel.Application")set objArgs = WScript.Arguments 'This tells us that we want to acept arugments for our scriptobjExcel.Visible = TrueobjExcel.Workbooks.AddintRow = 2intcolumn = 2objExcel.Cells(1, 1).Value = "Nombre Servidor"objExcel.Cells(1, 2).Value = "Administradores Locales"Set Fso = CreateObject("Scripting.FileSystemObject")Set InputFile = fso.OpenTextFile("D:SCRIPTSBuscar_AdministradoresMachineList.Txt")strGroup = "Administrators" 'We're setting strGroup to be equal to AdministratorsDo While Not (InputFile.atEndOfStream) HostName = InputFile.ReadLine Set objGroup = GetObject("WinNT://" & HostName & "/" & strGroup & ", group") Set WshShell = WScript.CreateObject("WScript.Shell") objExcel.Cells(intRow, 1).Value = HostName For Each objMember In objGroup.Members objExcel.Cells(intRow, intcolumn).Value = vbCrLf & objMember.Name 'Echoing out each member name and then a carriage return. intcolumn = intcolumn + 1 Next intcolumn = 2 intRow = intRow + 1LoopobjExcel.Range("A1:B1").SelectobjExcel.Selection.Interior.ColorIndex = 19objExcel.Selection.Font.ColorIndex = 11objExcel.Selection.Font.Bold = TrueobjExcel.Cells.EntireColumn.AutoFiAnonymous
January 16, 2014
Under an amendment if administrators want to add them to excel:http://sdrv.ms/1dTHLzZAnonymous
July 17, 2014
Doesn't work in win 8.1 client or host