/build/static/layout/Breadcrumb_cap_w.png

Return who is in the Local Administrators group using VBscrip and SMS 2003

Hello Everyone,

I have a script that is pushed from SMS 2003 on about 800 computers, the script should get a list of everyone who is in the local administrator group and stores it in a txt file. Problem is that Script runs on the first computer gets the information but will not work on the rest, can anyone please help.

thanks

Dim strComputer
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
'Create a FileSystemObject
Set oFS = CreateObject("Scripting.FileSystemObject")
'Open a text file of computer names
'with one computer name per line
Set objLogFile = oFS.OpenTextFile("\\myserver\App_Installs\Audit\Computers.txt", 8, True, 0)

Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("Group")
For Each objGroup In colGroups
If objGroup.Name = "Administrators" Then
objLogFile.WriteLine "************************************************************"
objLogFile.WriteLine strComputer
objLogFile.WriteLine vTab & objGroup.Name
For Each objUser in objGroup.Members
objLogFile.WriteLine vbTab & vTab & objUser.Name
Next
End If
objLogFile.close
Next

0 Comments   [ + ] Show comments

Answers (6)

Posted by: jmcfadyen 15 years ago
5th Degree Black Belt
0
Dim strComputer
you closed the logfile too soon (ps i never tested this but should work)


Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
'Create a FileSystemObject
Set oFS = CreateObject("Scripting.FileSystemObject")
'Open a text file of computer names
'with one computer name per line
Set objLogFile = oFS.OpenTextFile("\\myserver\App_Installs\Audit\Computers.txt", 8, True, 0)

Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("Group")
For Each objGroup In colGroups
If objGroup.Name = "Administrators" Then
objLogFile.WriteLine "************************************************************"
objLogFile.WriteLine strComputer
objLogFile.WriteLine vTab & objGroup.Name
For Each objUser in objGroup.Members
objLogFile.WriteLine vbTab & vTab & objUser.Name
Next
End If
Next
objLogFile.close
Posted by: atamo 15 years ago
Senior Yellow Belt
0
jmcfadyen

Thanks for your reply, I have already tried closing the file at the end but its still not working. What happens is that when SMS runs the script on the first computer then outputs to a log file the log file stays open preventing the script to run on the 2nd computer.

Thanks
Posted by: aogilmor 15 years ago
9th Degree Black Belt
0
I'd download ADSI scriptomatic, as AD deals specifically with groups. Regular Scriptomatic WMI might have a collection like that, check it out.

There also used to be an ISAdmin.exe utility. Look through the reskit, there might be something easier to use.
Posted by: bkelly 15 years ago
Red Belt
0
FYI, Admin Script Editor provides a simple wizard for generating ADSI queries in VBScript, PowerShell, KiXtart or AutoIt: http://www.adminscripteditor.com/editor/adsiwizard/
Posted by: rodtrent 15 years ago
Orange Belt
0
Folks have tried that before, but the problem exists where you can't keep a .txt file open by multiple computers at once, it gives a sharing violation. If you could somehow stagger each SMS client computer to run the script, it might work. However, SMS can't be managed this way.

Instead, you may want to rename the log file for each client, using the computename variable or something so that you have a bunch of log files instead of one giant one.
Posted by: anonymous_9363 15 years ago
Red Belt
0
Why bother with SMS? Could you not query AD for computers, interrogate them individually then write the log centrally? 800 machines will be a doddle overnight. There are a gazillion scripts around to interrogate AD and grab information. A good place to start is http://www.computerperformance.co.uk/vbscript/index.htm

A script I've used (and heavily adapted for my own purposes) for domain-wide activity is DomainReportManager.VBS, can be obtained here http://www.mousetrax.com/Downloads.html
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ