Re: Finding members of RDP groups of a list of computers

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"dave" <dave@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D63F1F90-9339-4C1E-9E86-841D95D11CE7@xxxxxxxxxxxxxxxx
got the script to work by double clicking the vbs file. Thanks again. if
i
want this to output to a txt file, what lines of code would i add to the
the
.vbs file for it to work when also double clicking on it rather than
running
cscript //nologo RDPMembers.vbs > report.txt from the command prompt?


A version of the program that writes to a text file (instead of echoing to
the command console):
==========
Option Explicit

Dim objFSO, strFile, objFile
Dim strComputer, objGroup, objMember
Dim strReport, objReport

Const ForReading = 1
Const ForWriting = 2
Const OpenAsASCII = 0
Const CreateIfNotExist = True

' Open text file with NetBIOS names of computers.
strFile = "c:\Scripts\computers.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)

' Open output file to write results.
Set objReport = objFSO.OpenTextFile(strReport, _
ForWriting, CreateIfNotExist, OpenAsASCII)

' Read file of computer names.
Do Until objFile.AtEndOfStream
strComputer = Trim(objFile.ReadLine)
' Skip blank lines.
If (strComputer <> "") Then
' Write computer name to output file.
objReport.WriteLine "Computer: " & strComputer
Set objGroup = GetObject("WinNT://" & strComputer _
& "/Remote Desktop Users,group")
For Each objMember In objGroup.Members
' Write group member names to output file.
objReport.WriteLine objMember.Name
Next
End If
Loop

' Clean up.
objFile.Close
objReport.Close
========
You can also modify this so the computer names and the members of the group
for that computer are on one comma delimited line. This file could then be
read by a spread*** program. This version would be as below:
==========
Option Explicit

Dim objFSO, strFile, objFile
Dim strComputer, objGroup, objMember
Dim strReport, objReport, strOutput

Const ForReading = 1
Const ForWriting = 2
Const OpenAsASCII = 0
Const CreateIfNotExist = True

' Open text file with NetBIOS names of computers.
strFile = "c:\Scripts\computers.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)

' Open output file to write results.
Set objReport = objFSO.OpenTextFile(strReport, _
ForWriting, CreateIfNotExist, OpenAsASCII)

' Read file of computer names.
Do Until objFile.AtEndOfStream
strComputer = Trim(objFile.ReadLine)
' Skip blank lines.
If (strComputer <> "") Then
' Document computer name.
strOutput = strComputer
Set objGroup = GetObject("WinNT://" & strComputer _
& "/Remote Desktop Users,group")
For Each objMember In objGroup.Members
' Write group member names to output file.
' Document group member names.
strOutput = strOutput & "," & objMember.Name
Next

' Write computer and group member names to output file in one
' comma delimited line.
objReport.WriteLine strOutput
End If
Loop

' Clean up.
objFile.Close
objReport.Close

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


.


Quantcast