Re: Please can some help me with this script
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 15 Aug 2007 09:12:59 -0500
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
.
- Follow-Ups:
- Re: Please can some help me with this script
- From: geniiw
- Re: Please can some help me with this script
- From: geniiw
- Re: Please can some help me with this script
- Prev by Date: Set Account Expiration Date for group in domain.
- Next by Date: Re: Set Account Expiration Date for group in domain.
- Previous by thread: Set Account Expiration Date for group in domain.
- Next by thread: Re: Please can some help me with this script
- Index(es):
Relevant Pages
|