Script to Collect Local Administrators Membership from List of Machines

Another script I wrote the other day, this one will take an input file called workstations.txt and produce a CSV which is easy to view in Excel and look at the local administrators group membership for the list of machines. The script could easily be modified to get the list from Active Directory although he framework I usually use for these is setup for a text file so I just export a list if AD is my source. The script will attempt to ping the machine before connecting in order to try and determine availability. If you have firewalls or routers filtering ICMP between the target machine and the host executing the script you may need to remove or modify this feature.

The script produces two files - a CSV and a log file. These three parameters are all configurable at the top by modifying lines 11 - 13:

Const LogFile = "LocalAdmins.log"
Const resultFile = "LocalAdministratorsMembership.csv"
Const inputFile = "c:\scripts\workstations.txt"

The script is attached below in a ZIP file. If you have any comments, bugs, etc, feel free to post them in the comments box below and I'll certainly take a look. Enjoy.

UPDATE: Script download URL - http://www.briandesmond.com/blog-attachments/dumplocaladministrators.zip

Posted Thursday, April 26 2007 8:30 AM by Brian Desmond | 34 Comments
Tagged as: ,

Comments, Trackbacks, & Pingbacks

#1 re: Script to Collect Local Administrators Membership from List of Machines

Monday, June 04 2007 12:21 PM by Mathieu CHATEAU

For those who renamed or get the administrator in other language (like administrateur in french), it may be better to dynamically get the administrator name:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select name from Win32_UserAccount where SID like 'S-1-5-21%-500'",,48)

For Each objItem in colItems

'''''changing password here

  Next

#2 re: Script to Collect Local Administrators Membership from List of Machines

Tuesday, November 27 2007 9:37 AM by Alex

I have no scripting knowledge and I have tired this script and its great, is there anyway to add local user accounts to this as well?

#3 re: Script to Collect Local Administrators Membership from List of Machines

Monday, December 03 2007 3:10 PM by Nick

Is there a way to turn off all of the pop up boxes that require user interaction?  I have a large number of server to run this on and I don't want to sit and click "OK" all day.

#4 re: Script to Collect Local Administrators Membership from List of Machines

Monday, December 03 2007 4:18 PM by Nick

I figured out that if I delete the lines that have "Write.Echo" then that would take care of my issue.

#5 re: Script to Collect Local Administrators Membership from List of Machines

Wednesday, December 19 2007 8:51 AM by Andrea

The script is great! Thank you!!

#6 re: Script to Collect Local Administrators Membership from List of Machines

Thursday, January 10 2008 1:38 PM by Ken

What would be needed to change this script to output the active directory name?  (ie.  Domain\user)

#7 re: Script to Collect Local Administrators Membership from List of Machines

Monday, January 14 2008 1:23 PM by Valdemar Junior

How do I put this script a user called Administrador (BRAZIL)

e-mail: jnrcarvalho@gmail.com

#8 re: Script to Collect Local Administrators Membership from List of Machines

Tuesday, April 22 2008 5:58 AM by Aryan

Thanx buddy it works !!

#9 re: Script to Collect Local Administrators Membership from List of Machines

Thursday, July 10 2008 11:50 PM by KP

Works great, but like the comment posted by Ken. "What would be needed to change this script to output the active directory name?  (ie.  Domain\user)" I can't distinguish between the accounts since I have multiple domains.  Any help would be appreciated. email: kp4678@hotmail.com

#10 re: Script to Collect Local Administrators Membership from List of Machines

Friday, September 26 2008 9:54 AM by ritesh

A great script for Network Administrators

#11 re: Script to Collect Local Administrators Membership from List of Machines

Friday, September 26 2008 10:00 AM by Hindulok

Hi Brian,

Where is the zip file? I can't find it. Please help

#12 re: Script to Collect Local Administrators Membership from List of Machines

Wednesday, November 12 2008 4:34 AM by Mario

But where is the zip file ?

#13 re: Script to Collect Local Administrators Membership from List of Machines

Saturday, November 15 2008 9:48 PM by brian desmond

I added the link to the missing zip. I've got it on my list to internationalize the script so it handles non-english strings gracefully. Thanks!

#14 re: Script to Collect Local Administrators Membership from List of Machines

Monday, December 29 2008 12:18 PM by marco

didn´t work, show me the message "did not respond to ping".

I tried with files .csv and .txt

#15 re: Script to Collect Local Administrators Membership from List of Machines

Monday, December 29 2008 6:49 PM by Brian Desmond

Hi Marco-

The script expects machines to respond to an ICMP ping in order to query the group membership on them. If you've got a firewall blocking the pings you'll need to modify the script to not have this pre-requisite check.

I've added a suggestion to my list to see about making the ping check optional.

#16 re: Script to Collect Local Administrators Membership from List of Machines

Monday, January 12 2009 3:37 AM by Erik

Nice working script. I only removed the wscript.echo lines because it made me click a lot :)

#17 re: Script to Collect Local Administrators Membership from List of Machines

Sunday, February 15 2009 6:54 PM by Anonymous

Ha ha ha! Look, the Windows idiots think they can script. You people honestly think DOS is capable of scripting like BASH can?

Enjoy your toy shell, the *nix community will use real command lines.

#18 re: Script to Collect Local Administrators Membership from List of Machines

Monday, February 16 2009 10:28 AM by Paul

well... vb scripting host isn't a shell, has nothing to do with the command line and to be honest PowerShell pretty much spanks the day lights out of Bash.

But hey keep up the pithy comments. It was irrational comments like this that got Microsoft to deliver something like PS in the first place. So good work Anonymous Open Source proponent with no clue!

#19 re: Script to Collect Local Administrators Membership from List of Machines

Friday, April 03 2009 7:09 AM by Stephen

Excellent Script - Thanks for making this available - saving me a lot of time. But.. here is a question - can you make it - either remove the workstations that is has successfully queried from workstations.txt or generate a new worksations file with a list of thoes that failed to respond? :-) Cheer

PS good response to Anonymous - makes you wonder, Why?

#20 re: Script to Collect Local Administrators Membership from List of Machines

Thursday, September 10 2009 4:42 PM by Esteban Blanco

I know zero about scripting so I am struggling with this. Do I take all the machines from AD (export them) and put them in a text file? Once I have this file then just run it against that file? I am sorry for my ignorance. What's sad is that I am an MCP, MCSE, MCTS, MCITP. I am very embarrassed but I have never had the need to script until now and I never learned it. I am a quick learner though so if anyone has the patience to assist me, I can talk shop, I am just confused.

To "anonymous". Why would you be even on this website when BASH commands rule? You would think you would have no need to come here and look at the website in the first place. Second, if you want to be an "Internet tough guy" at least have the balls to put your name and email address. You have mine, you can contact me anytime and we can talk you coward.

Thank you Brian for this awesome resource. I am sure when I get a clue about scripting then I will be able to have a field day with this! If you need help with Spanish stuff I speak and write it fluently.

Esteban Blanco

#21 re: Script to Collect Local Administrators Membership from List of Machines

Thursday, September 10 2009 4:46 PM by Brian Desmond

Yes it's one machine per line

#22 re: Script to Collect Local Administrators Membership from List of Machines

Wednesday, November 04 2009 9:06 PM by Hendra

this script is GREAT!! really appreciate it..thanks.

#23 re: Script to Collect Local Administrators Membership from List of Machines

Thursday, November 12 2009 1:51 PM by Rich

Seems like it will work well, however, I am receiving an error when I start it up:

Line:50

Char: 3

Error: The network path was not found.

Code: 80070035

Source: (null)

Any help would be greatly appreciated.

#24 re: Script to Collect Local Administrators Membership from List of Machines

Sunday, December 13 2009 4:20 PM by Johnny

Thanks for the posting of this script. I found it very helpful since my skills at writing these are almost null.

#25 re: Script to Collect Local Administrators Membership from List of Machines

Monday, January 04 2010 7:47 AM by dejan

@Rich

I recieve the same error, because the one of the computers from a list has the duplicate ip address. After removing from the list, everything running fine.

Thanks for script, its very usefull.

#26 re: Script to Collect Local Administrators Membership from List of Machines

Monday, January 04 2010 6:02 PM by Satish

Nice Script..Thanks

#27 re: Script to Collect Local Administrators Membership from List of Machines

Tuesday, January 05 2010 5:01 AM by Eric

I would think this script is what I need. But a message appears: "Computername did not respond to ping". a manual ping however gives me a response as an answer. Any idee,

Thanks

Eric

#28 re: Script to Collect Local Administrators Membership from List of Machines

Thursday, January 21 2010 6:30 AM by TR

This is nice script which made life easy in collecting local admins on multiple servers. However, how would I get the output with domain name like domain\user or machine\user. Any help is greatly appreciated.

Thank you again for your script.

#29 re: Script to Collect Local Administrators Membership from List of Machines

Thursday, March 18 2010 2:01 PM by Andrew Sharp

Thank you very much for this script. It seems to work very well, however i'm running into a problem where every now and then it comes to machine on my txt file and the script just stops. In viewing the log entry it always shows that machine responded to a ping. If i edit the txt file remove the computer, it will resume, but eventually does the same thing on another computer. I know that the on error resume command is in your script. Was wondering if you had any advice?

Thanks again, this is a great tool

#30 re: Script to Collect Local Administrators Membership from List of Machines

Thursday, March 18 2010 2:16 PM by Andrew Sharp

RE: #29

Think i figured it out. Looks like resume on error was commented out. Its working beautifully now, thank you again so much.

#31 re: Script to Collect Local Administrators Membership from List of Machines

Thursday, April 15 2010 9:59 AM by Jeff

Instructions for those who are confused...

Extract the zip file to some folder.

Open the VBS file in a standard text editor like notepad.

Modify this line:

Const inputFile = "c:\work\local\workstations.txt"

And input a valid path to a file named workstations.txt.

I also highly recommend you edit the rest of the file to eliminate any popups. To do so, simply place a ' mark (next to the enter key) at the very beginning of each line that contains the word echo. So this:

WScript.Echo line & " responded to ping"

becomes this:

'WScript.Echo line & " responded to ping"

Workstations.txt should contain a list of PCs on your network, only the PC name. No other characters like backslashes. Example:

pcname1

pcname2

pcname3

You can get a list of PCs fairly easily as follows:

open a DOS box, enter:

net view > pclist.txt

Open pclist.txt with excel, do a text to columns, first filtering on the \ character, then filtering on tabs and spaces. When complete, one of the columns should contain only a PC list. Copy and paste this list into a new text file, it should be the same name and path as you modified the VBS script above.

Thanks for the script.

#32 re: Script to Collect Local Administrators Membership from List of Machines

Friday, July 30 2010 5:23 AM by Rajneesh

Hi,

Can you Please provide the script which collect all the local groups and their members from list of machines.

i will be thanksfull if you can also add the code to get the details of shared folders and the seucrity permission to these shared folders.

Thanks

#33 re: Script to Collect Local Administrators Membership from List of Machines

Friday, July 30 2010 5:23 AM by Rajneesh

Hi,

Can you Please provide the script which collect all the local groups and their members from list of machines.

i will be thanksfull if you can also add the code to get the details of shared folders and the seucrity permission to these shared folders.

Thanks

#34 re: Script to Collect Local Administrators Membership from List of Machines

January 18, 2009 7:36 AM by Controllare appartenenza gruppi locali via script | hilpers

Pingback from Controllare appartenenza gruppi locali via script | hilpers

Leave a comment