Re: Please can some help me with this script

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I would recommend not using "On Error Resume Next" as it makes
troubleshooting very difficult. Without this statement, the script you
posted ran fine for me, except for an error raised on the last line of the
file, which because the last entry ended with a carriage return, was blank.
This is very common (to have blank lines). I avoid it by testing for it.
Other than that the script ran fine.

However, why do you list the group name in parentheses after the group name?
Do you mean to list some other property of the group? Also, you no longer
document the group memberships, as you did in your previous script. Finally,
I assume you use a dictionary object to avoid duplicate names, but you don't
check for duplicates. This may be raising an error for you; it did not for
me because I did not have duplicate names. To check for duplicates, you
should reverse the order when you add to the dictionary object. That is use:

objDictionary.Add strNextLine, i

This also makes it easier to enumerate the server names. To test for blank
lines and check for duplicate computer names the script could be:
================
'List the Local groups on a Set of Computers

Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
' Make dictionary entries case insensitive.
objDictionary.CompareMode = vbTextCompare
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\TEMP\dry_servers.txt", ForReading)
i = 0

Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
' Skip blank lines.
If (strNextLine <> "") Then
' Skip duplicates.
If Not objDictionary.Exists(strNextLine) Then
' Add computer name as key in dictionary object,
' so we can check for duplicate names.
objDictionary.Add strNextLine, i
i = i + 1
End If
End If
Loop

For Each strComputer in objDictionary
Set objComputer = GetObject("WinNT://" & strComputer)
objComputer.Filter = Array("group")
WScript.Echo "_______________________________________"
WScript.Echo "Computer: " & strComoputer
WScript.Echo "_______________________________________"
For Each objgroup in objComputer
Wscript.Echo objgroup.name & "(" & objgroup.Name & ")"
Next
WScript.Echo "---------------------------------------"
WScript.Echo "Last Entry for:" & strComputer
WScript.Echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Next
================
If you also want to document group membership, as you did before, simply add
the nested For Each/Next loop. For example, adding this to the existing
loop:
==========
For Each strComputer in objDictionary
Set objComputer = GetObject("WinNT://" & strComputer)
objComputer.Filter = Array("group")
WScript.Echo "_______________________________________"
WScript.Echo "Computer: " & strComoputer
WScript.Echo "_______________________________________"
For Each objgroup in objComputer
Wscript.Echo objgroup.name & "(" & objgroup.Name & ")"
' Document direct group membership.
For Each objUser In objGroup.Members
Wscript.Echo "-- Member: " & objUser.Name
Next
Next
WScript.Echo "---------------------------------------"
WScript.Echo "Last Entry for:" & strComputer
WScript.Echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Next
===========
I hope this helps.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"geniiw" <geniiw@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:AB9FB1C7-51BF-4F3D-B819-3C176EAC7058@xxxxxxxxxxxxxxxx
I want to modify the script below to pull off local groups and there
members
from a text file listing the names of the servers. Any help greatly
appreciated.

'List the Local groups on a Set of Computers

On Error Resume Next
Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\TEMP\dry_servers.txt",
ForReading)
i = 0

Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop

For Each objItem in objDictionary
Set objComputer = GetObject("WinNT://" & objDictionary.Item(objItem) & "")
objComputer.Filter = Array("group")
WScript.Echo "_______________________________________"
WScript.Echo "Computer: " & objDictionary.Item(objItem)
WScript.Echo "_______________________________________"
For Each objgroup in objComputer
Wscript.Echo objgroup.name & "(" & objgroup.Name & ")"
Next
WScript.Echo "---------------------------------------"
WScript.Echo "Last Entry for:" & objDictionary.Item(objItem)
WScript.Echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Next



.



Relevant Pages

  • Re: Please can some help me with this script
    ... Other than that the script ran fine. ... I assume you use a dictionary object to avoid duplicate names, ... objDictionary.Add strNextLine, i ...
    (microsoft.public.windows.server.scripting)
  • Re: Please can some help me with this script
    ... the strComputer variable was spelled wrong and once I ... Other than that the script ran fine. ... I assume you use a dictionary object to avoid duplicate names, ... objDictionary.Add strNextLine, i ...
    (microsoft.public.windows.server.scripting)
  • Re: Please can some help me with this script
    ... Thank you so much for your reply the script ran but it did not include the ... -- Member: Enterprise Admins ... I assume you use a dictionary object to avoid duplicate names, ... objDictionary.Add strNextLine, i ...
    (microsoft.public.windows.server.scripting)
  • Re: Seperating CSV rows into new, seperate files
    ... of a script but it still has one more problem. ... will import the list will ignore duplicate rows. ... >> and I am working on a way to parse a CSV file of class lists from MS ... The difference is that the session number changes. ...
    (comp.lang.python)
  • Re: ("Scripting.Dictionary") buffer
    ... RAM I managed to populate a dictionary object with 18,000 Distinguished ... My test script was slow, ... ' Sub to enumerate users in OU/Container and child containers. ...
    (microsoft.public.scripting.vbscript)