Windows Server - Please can some help me with this script
Asked By genii
15-Aug-07 08:52 AM

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
Scripting.FileSystemObject
(1)
ObjTextFile.AtEndOfStream
(1)
ObjFSO.OpenTextFile
(1)
Scripting.Dictionary
(1)
ObjDictionary.CompareMode
(1)
ObjTextFile.Readline
(1)
VbTextCompare
(1)
QCAdmin
(1)
Richard Mueller [MVP] replied...

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
--
genii replied...
Mr. Mueller,
Thank you so much for your reply the script ran but it did not include the
computer(server name) so I have no idea what server the groups or members
correspond too. Please see exerpt below.
_______________________________________
Computer:
_______________________________________
Account Operators(Account Operators)
-- Member: QCAdmin
Administrators(Administrators)
-- Member: jroot
-- Member: Enterprise Admins
-- Member: Domain Admins
-- Member: SMS&_PRODDC03
-- Member: SMS&_PRODDC04
-- Member: SMS&_PRODDC99
-- Member: SMS#_PRODDC02
-- Member: service_adbackup
Backup Operators(Backup Operators)
Distributed COM Users(Distributed COM Users)
Guests(Guests)
-- Member: Domain Guests
-- Member: JTrain
-- Member: IUSR_PRODDC01
-- Member: IWAM_PRODDC01
genii replied...
I found the problem. the strComputer variable was spelled wrong and once I
declared all of the varaibles using "dim" I found the problem. Again thank
you so much for your help.
Genii
Richard Mueller [MVP] replied...
Sorry about the spelling. I was typing too fast. That's why I like Option
Explicit.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

Dim FileName, OutputName, Marker, CRLF, p Dim oFSO, oArgs, Input, InputStream, objOutFile Set oFSO = CreateObject("Scripting.FileSystemObject") Set oArgs = WScript.Arguments Marker = Chr(183) CRLF = Chr(13) & Chr(10) FileName = objArgs(0 ObjWshShell.Environment ("PROCESS")("temp")· Tempname1 = temp & .tmp"· · Err.Clear· On Error Resume Next · Set objStream = objFSO.OpenTextFile(Te mpname1, ForWriting, True)· If Err.numbe r <> 0 Then· WScript.Echo ("Cannot open Echo Status = WshRunning· WScript.Sleep 100· Loop·· Err.Clear· On Error Resume N ext· Set InputFile = objFSO.OpenTextFile (Tempname2)· If Err.number <> 0 Then· W Script.Echo ("Cannot access """ & TempNa me2 & """.")· WScript.Echo 10) AccessDenied = False main() ' = = = = = = = = = = = = = = 'Main module ' = = = = = = = = = = = = = = Sub main Dim Help, objFSO, objArgs Set objFSO = CreateObject("Scripting.FileSystemObject") Set ObjWshShell = WScript.CreateObject("WScript.Shell") Help = "RDir Version 1.4 by Pegasus.30.10
name on command line has maximum length of 28 characters / / = = = = = = = = = = = = = = = = = = = = = = = = = = = [ Variables ] = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = var fso = new ActiveXObject("Scripting.FileSystemObject"); var FileHandle, ExitStatus = 0, BackupStatus = 0; var ForReading = 1, ForWriting = 2, ForAppending = 8; var EmailBody var ExitCode, LogF = 0x2; if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, "FsCheckFileExists"); var fso = new ActiveXObject("Scripting.FileSystemObject"); ExitCode = fso.FileExists(FileName) if (FsLogFlag(LogF)) { if (ExitCode) IoLogEvent("content", LogHandle, FileName +" does exist LogHandle) { var ExitCode, LogF = 0x200; if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, ""); var fso = new ActiveXObject("Scripting.FileSystemObject"); ExitCode = fso.FolderExists(FolderName) if (FsLogFlag(LogF)) { if (ExitCode) IoLogEvent("content", LogHandle, "FsCheckFolderExists success: else FileName, LogHandle) && Overwrite) | | (!FsCheckFileExists(FileName, LogHandle))) { if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, ""); fso = new ActiveXObject("Scripting.FileSystemObject"); f = fso.CreateTextFile(FileName, Overwrite, Unicode); f.Close(); if (FsLogFlag(LogF)) { IoLogEvent("content", LogHandle, "FsFileCreate
anybody knows how to do this? Thanks in advance, Marcus Windows 2000 Active Directory Discussions Scripting.FileSystemObject (1) ObjFSO.OpenTextFile (1) StrNetBIOSDomain (1) ObjFile.AtEndOfStream (1) NetBIOS (1) ObjTextFile.WriteLine (1) What is the format strFile = "c: \ scripts \ organization.csv" ' Open the text file for read access. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFile, ForReading) ' Read each line of the file. Do Until objFile.AtEndOfStream strLine = Trim(objFile
hostnames.txt" hostlog = "c: \ hostlog.txt" Const ForWriting = 2 Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objInputFile = objFSO.Opentextfile(hostnames, ForReading, True) Set OutputFile = objfso.OpenTextFile(hostlog, ForWriting, True) Do Until objInputFile.atEndofStream strComputer = objInputFile.ReadLine Set objPing = GetObject("winmgmts:{impersonationLevel Next Loop objInputFile.Close INPUT_FILE_NAME = "C: \ hostlog.txt" Outputfile = "C: \ host2.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FORREADING) Set OutputFile = objfso.CreateTextFile(Outputfile, ForWriting, True) strComputers = objFile
could try this script: sServerList = "d: \ temp \ Servers.txt" sOutputFolder = "d: \ temp \ " Set oFSO = CreateObject("Scripting.FileSystemObject") Set oServerList = oFSO.OpenTextFile(sServerList) While Not oServerList.AtEndOfStream ProcessServer(oServerList.ReadLine) Wend oServerList.Close C: \ DST" Set objNet = CreateObject("WScript.NetWork") Set objComputer = CreateObject("Shell.LocalMachine") Set oFSO = CreateObject("Scripting.FileSystemObject") Set oServerList = oFSO.OpenTextFile(sServerList) While Not oServerList.AtEndOfStream ProcessServer(oServerList.ReadLine) Wend oServerList.Close root \ cimv2") Set objNet = CreateObject("WScript.NetWork") Set objComputer = CreateObject("Shell.LocalMachine") Set objFSO = CreateObject("Scripting.FileSystemObject") Set oFilesys = CreateObject("Scripting.FileSystemObject") Set oFiletxt = oFilesys.CreateTextFile("C: \ DST \ server_dst.log", True) sPath = oFilesys.GetAbsolutePathName("C: \ DST \ server_dst