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
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)
Please log in to answer
Posted by:
jmcfadyen
16 years ago
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
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
16 years ago
Posted by:
aogilmor
16 years ago
Posted by:
bkelly
16 years ago
Posted by:
rodtrent
16 years ago
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.
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
16 years ago
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
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.
so that the conversation will remain readable.