Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Frankenstein VBScript for All local admins - small issues...

Avatar of JamesBills
JamesBillsFlag for United States of America asked on
Programming Languages-OtherScripting LanguagesVB Script
10 Comments1 Solution635 ViewsLast Modified:
Let me start off by saying I have almost no idea what I'm doing when it comes to scripting.

I want to be able to run this script and have it tell me what accounts/groups are in the Administrators group (local admins) for every server in our network, and then I added it giving me the members of those domain groups if present. However we have several road blocks or hoops to jump through or around...

We have four domains... DNS isn't being properly maintained and isn't correct sometimes... We can't ping across subnets/vlans (for the most part)... we have some servers that aren't part of a domain at all... and one single account doesn't have the rights to access the info needed...

I figured the list to pull from should be by IP to overcome the DNS issues...

I'm pretty sure I'm going to have to run this script from each DC as a domain admin from that domain...

I like the output into CSV as it's easily viewable/presentable in excel..

Now I combined 2 scripts to give me the info I want (see below).  Now I need to work on some presentation and possible better ways to go about it, and there is still one major problem with this script...

this is the biggy... It appears that when it comes across a server that it can't pull the info it needs from it just writes the last good info it had in it's place... so it's giving me the info for a different server but labeling it wrong. I need a way to clear the collected info after each data pull/get so that when it loops and comes across a server it can't pull from or communicate with it writes blank... or even a little message would be nice but not required... just an easy way to distinguish it didn't pull the info from that server... like I said before, ping doesn't work 100% of the time.

3 little issues I would like some help on...

I wrote it to label each section with the IP from the list it's using (strComputer)... If possible I'd rather have it pull the computer name directly from the server it's accessing and use that in addition to the label, and again wipe the collection each time so as to not write the wrong data over again... maybe something like
 w.writeline strComputer & "(" & strComputerName & ")"
or something... as long as I have the variable to pull from I can format it however...

I would like to be able to put the server section label in bold as well as the group name before it lists the group members... I can't figure it out... I don't understand the output properties enough. I tried [b] and [/b] and it ofcourse didn't work... i thought i was on to something with w.writeline.font.bold = true... but honestly don't have a clue...

I would also like to pull the class of the domain group members as well and place them in the same column with the other obj class pull from the first pull/get ouput (objMember.class)... I tried objDomainMember.class but it didn't work...

Again, I figured out how to combine 2 different scripts and a lot of the formatting and everything just by trial and error... I don't really have a clue what I'm doing... lol... so any errors or better ways of doing things or syntax or whatever feel free to help correct...

Thanks for any help... all will be greatly appreciated...

p.s. wow... sorry for the novel... just wanted to be as detailed as possible...

on error resume Next
const ForReading = 1
const ForWriting = 2
const ForAppending = 8
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oTS = oFS.OpenTextFile("serveriplist.txt",ForReading)
Set ws = CreateObject ("Scripting.FileSystemObject")
Set w = ws.OpenTextFile (".\Admin Members.csv", ForAppending, True)
w.WriteLine "Information Collection started at " & now
Do Until oTS.AtEndOfStream
strComputer = oTS.Readline
strTestString = "/" & strComputer & "/"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
w.writeLine ""
w.writeLine strComputer
w.writeLine ""
w.writeLine ""
For Each objMember in objGroup.Members
    mem = objMember.adspath
      w.writeline strComputer & "," & right(mem,len(mem)-8) & "," & objMember.class
w.writeline ""
For Each objMember In objGroup.Members
    If objMember.Class = "Group" Then
        If Not InStr(objMember.AdsPath, strTestString) Then
            Set objDomainGroup = GetObject(objMember.AdsPath)
            w.writeline objDomainGroup.Name & " , " & right(objDomainGroup.adspath,len(objDomainGroup.adspath)-8)
            For Each objDomainMember in objDomainGroup.Members
                w.writeline objDomainMember.FullName & " , " & right(objDomainMember.adspath,len(objDomainMember.adspath)-8)
            w.writeline ""
        End If
    End If
MsgBox "Finished collecting info."
Avatar of sirbounty
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answers