vhaperbaugub
asked on
VB Script to Check Administrator Group on a List of PC's
Hello - I need a VB script that will run against a list of PC's and report back which users/groups are in the Administrators Group on the PC's.
ASKER
Hello - I got this error: C:\FindAdmin.vbs(30, 25) Microsoft VBScript compilation error: Expected end of statement
Sorry Friday fingers in operation
Replace this line
Set oFile = objFSO.OpenTextFile("C:\Li stOfPCs.tx t", ForReading)
With this
Set oFile = oFSO.OpenTextFile("C:\List OfPCs.txt" , ForReading)
Code tested.
Jawa29
Replace this line
Set oFile = objFSO.OpenTextFile("C:\Li
With this
Set oFile = oFSO.OpenTextFile("C:\List
Code tested.
Jawa29
ASKER
Hello - Now I'm getting this error:
C:\FindAdmin.vbs(31, 25) Microsoft VBScript compilation error: Expected end of statement
C:\FindAdmin.vbs(31, 25) Microsoft VBScript compilation error: Expected end of statement
Can you paste your exact code please?
Jawa29
Jawa29
ASKER
Const ForReading = 1
Const ForWriting = 2
On Error Resume Next
Set oFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set oFile = oFSO.OpenTextFile("C:\List OfPCs.txt" , ForReading)
Do Until oFile.AtEndOfStream
sComputer = oFile.ReadLine
sTxt = sTxt & "--" & sComputer & "--" & vbCRLF
Set oGroup = GetObject("WinNT://" & sComputer & "/Administrators,group")
For Each oUser in oGroup.Members
sTxt = sTxt & oUser.Name & vbCRLF
Next
sTxt = sTxt & "----------"
Loop
Set oTextFile = oFSO.OpenTextFile("C:\List OfPCs-Resu lts.txt", ForWriting, True)
oTextFile.WriteLine(sTxt)
oTextFile.Close
Set oFSO = Nothing
Set oFile = Nothing
Set oGroup = Nothing
WScript.Quit
Toggle HighlightingOpen in New WindowSelect All
Const ForWriting = 2
On Error Resume Next
Set oFSO = CreateObject("Scripting.Fi
Set oFile = oFSO.OpenTextFile("C:\List
Do Until oFile.AtEndOfStream
sComputer = oFile.ReadLine
sTxt = sTxt & "--" & sComputer & "--" & vbCRLF
Set oGroup = GetObject("WinNT://" & sComputer & "/Administrators,group")
For Each oUser in oGroup.Members
sTxt = sTxt & oUser.Name & vbCRLF
Next
sTxt = sTxt & "----------"
Loop
Set oTextFile = oFSO.OpenTextFile("C:\List
oTextFile.WriteLine(sTxt)
oTextFile.Close
Set oFSO = Nothing
Set oFile = Nothing
Set oGroup = Nothing
WScript.Quit
Toggle HighlightingOpen in New WindowSelect All
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was wierd.....its working now....Thanks!!!!!!!!!!!!!
ASKER
Just wondering.....is there a way to add a progress bar or something to the script? When you do a couple thousand PC's at once the screen remains blank.....Thanks again.
The only real way to do that effectivly is to run the script using cscript and add a Wscript.Echo in there.
Something like:
Do Until oFile.AtEndOfStream
sComputer = oFile.ReadLine
sTxt = sTxt & "--" & sComputer & "--" & vbCRLF
Set oGroup = GetObject("WinNT://" & sComputer & "/Administrators,group")
For Each oUser in oGroup.Members
sTxt = sTxt & oUser.Name & vbCRLF
Next
sTxt = sTxt & "----------"
Wscript.Echo sComputer
Loop
If you add this then just double click the file it will constantly pop up a window with the computer name has just completed and not continue until you select OK.
I use VBSEdit which allows you to run scripts as cscript which outputs to a window.
If you want to run the script in script from a command window just type in cscript C:\scriptname.vbs
Jawa29
Something like:
Do Until oFile.AtEndOfStream
sComputer = oFile.ReadLine
sTxt = sTxt & "--" & sComputer & "--" & vbCRLF
Set oGroup = GetObject("WinNT://" & sComputer & "/Administrators,group")
For Each oUser in oGroup.Members
sTxt = sTxt & oUser.Name & vbCRLF
Next
sTxt = sTxt & "----------"
Wscript.Echo sComputer
Loop
If you add this then just double click the file it will constantly pop up a window with the computer name has just completed and not continue until you select OK.
I use VBSEdit which allows you to run scripts as cscript which outputs to a window.
If you want to run the script in script from a command window just type in cscript C:\scriptname.vbs
Jawa29
The code below should do the trick, just create a text file on you C: called ListOfPCs.txt with each PC on it's own line and this script will work.
Remember to run this as a Domain Admin or else you won't be able to query the PC remotely.
Jawa29
Open in new window