Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Finding members of RDP groups of a list of computers

Reply
 
Old 06-19-2009   #11 (permalink)
dave


 
 

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

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?

"Richard Mueller [MVP]" wrote:
Quote:

> As a last resort you can double click on the file RDPMembers.vbs in Windows
> Explorer. This will run the program with the default host program on your
> computer, most likely wscript.exe. The program will run, but you will get a
> message box for each computer and each member of the group on the computer.
> You will need to click to acknowledge each message box. However, once you
> find the file in Windows Explorer, this should help you navigate in the
> command prompt window to the folder where it is saved.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
> message news:OsGJ3NI8JHA.1252@xxxxxx
Quote:

> > You are not in the directory (folder) where the file RDPMembers.vbs is
> > saved. Your text file of computer names must be located in a folder on
> > your computer. It would be best to save the file RDPMembers.vbs
> > (containing the VBScript program I posted earlier) in the same folder.
> > When you get to a command prompt you must navigate to this folder. If the
> > folder is c:\Scripts, the command in the command console window would be:
> >
> > cd c:\Scripts
> >
> > The "cd" command means change directory. After this the prompt in the
> > window will probably be:
> >
> > c:\Scripts
> >
> > indicating you are in the Scripts folder on drive c:. If your folder or
> > path includes any spaces, enclose the folder in quotes. For example, if
> > RDPMembers.vbs is saved in "c:\My Folder", the command at a command prompt
> > would be:
> >
> > cd: "c:\My Folder"
> >
> > You can check if the file RDPMembers.vbs is in the folder with the "dir"
> > command:
> >
> > dir RDPMembers.vbs
> >
> > The command processor will indicate the file name, size, and date. Or, if
> > the file is not found, will display "File not found".
> >
> > Most administrative scripts are run at a command prompt this way. The
> > alternative is to add a great deal more code to the program so it writes
> > output to a text file, but then you still need to find that output file. I
> > hope this helps.
> >
> > --
> > Richard Mueller
> > MVP Directory Services
> > Hilltop Lab - http://www.rlmueller.net
> > --
> >
> > "dave" <dave@xxxxxx> wrote in message
> > news:BA402293-324D-4AB4-9246-AC3B5D41F214@xxxxxx
Quote:

> >> Hi Richard. Thanks for that. But i'm unable to get it to run. all i
> >> get is
> >> the RDPMembers.vbs does not exists message. I know i'm doing something
> >> wrong. but don't know what.
> >>
> >> "Richard Mueller [MVP]" wrote:
> >>
> >>> You are correct. Save the program in a file with *.vbs extension, such
> >>> as
> >>> RDPMembers.vbs. Save the computer NetBIOS names, one name per line, in a
> >>> text file, perhaps computers.txt. The path for this file is hard coded
> >>> in
> >>> the program, so you need to modify this line:
> >>>
> >>> strFile = "c:\Scripts\computers.txt"
> >>>
> >>> for your situation. I like to save VBScript programs in my own folder.
> >>> Launch a command prompt. I use the "Run..." feature and enter cmd.exe.
> >>> You
> >>> can also create a shortcut to cmd.exe and place it on your desktop. In
> >>> the
> >>> command prompt, navigate to the folder where the file RDPMembers.vbs is
> >>> saved. Then enter the command:
> >>>
> >>> cscript //nologo RDPMembers.vbs
> >>>
> >>> This tells the cscript.exe host program to run the program
> >>> RDPMembers.vbs.
> >>> The //nologo optional parameter means to not display logo information.
> >>> If
> >>> the file RDPMembers.vbs is not in the current directory, include the
> >>> path.
> >>> For example:
> >>>
> >>> cscript //nologo c:\scripts\RDPMembers.vbs
> >>>
> >>> The program as written displays the computer names and group member
> >>> names in
> >>> the console. You can redirect this output to another text file. For
> >>> example:
> >>>
> >>> cscript //nologo RDPMembers.vbs > report.txt
> >>>
> >>> I hope this helps.
> >>>
> >>> --
> >>> Richard Mueller
> >>> MVP Directory Services
> >>> Hilltop Lab - http://www.rlmueller.net
> >>> --
> >>>
> >>> "dave" <dave@xxxxxx> wrote in message
> >>> news:CD288B38-E092-48C8-B490-5266F17C51EC@xxxxxx
> >>> > Hi Richard,
> >>> >
> >>> > Thanks for the quick response. I do not know much about scripting so
> >>> > if
> >>> > you
> >>> > could guide me through this it would be great
> >>> >
> >>> > i assume i save this script as .vbs?
> >>> > put a txt file called computers in the same folder when running?
> >>> > how do i run at a command prompt using cscript?
> >>> >
> >>> >
> >>> >
> >>> > "Richard Mueller [MVP]" wrote:
> >>> >
> >>> >>
> >>> >> "dave" <dave@xxxxxx> wrote in message
> >>> >> news:767DA0FC-D26E-42DB-AC07-778EF8AEACEA@xxxxxx
> >>> >> > Title pretty much says it all
> >>> >> >
> >>> >> > I'm trying to find a script which will find the members of the rdp
> >>> >> > group
> >>> >> > from a list of PC's on a domain from a txt file
> >>> >> >
> >>> >> > Can anyone help?
> >>> >>
> >>> >> I assume you mean the local "Remote Desktop Users" group on each
> >>> >> computer.
> >>> >> You can use the FileSystemObject to read the text file of computer
> >>> >> names,
> >>> >> then bind to the local group on each computer using the WinNT
> >>> >> provider.
> >>> >> You
> >>> >> can use the Members method of the group object to enumerate the
> >>> >> direct
> >>> >> members and echo their names to the console. For example:
> >>> >> ==========
> >>> >> Option Explicit
> >>> >>
> >>> >> Dim objFSO, strFile, objFile
> >>> >> Dim strComputer, objGroup, objMember
> >>> >>
> >>> >> Const ForReading = 1
> >>> >>
> >>> >> strFile = "c:\Scripts\computers.txt"
> >>> >> Set objFSO = CreateObject("Scripting.FileSystemObject")
> >>> >> Set objFile = objFSO.OpenTextFile(strFile, ForReading)
> >>> >>
> >>> >> Do Until objFile.AtEndOfStream
> >>> >> strComputer = Trim(objFile.ReadLine)
> >>> >> If (strComputer <> "") Then
> >>> >> Wscript.Echo "Computer: " & strComputer
> >>> >> Set objGroup = GetObject("WinNT://" & strComputer _
> >>> >> & "/Remote Desktop Users,group")
> >>> >> For Each objMember In objGroup.Members
> >>> >> Wscript.Echo objMember.Name
> >>> >> Next
> >>> >> End If
> >>> >> Loop
> >>> >>
> >>> >> objFile.Close
> >>> >> =======
> >>> >> This should be run at a command prompt using cscript. You can
> >>> >> redirect
> >>> >> the
> >>> >> output to a text file.
> >>> >>
> >>> >> --
> >>> >> Richard Mueller
> >>> >> MVP Directory Services
> >>> >> Hilltop Lab - http://www.rlmueller.net
> >>> >> --
> >>> >>
> >>> >>
> >>> >>
> >>>
> >>>
> >>>
> >
> >
>
>
>

My System SpecsSystem Spec
Old 06-19-2009   #12 (permalink)
Richard Mueller [MVP]


 
 

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


"dave" <dave@xxxxxx> wrote in message
news63F1F90-9339-4C1E-9E86-841D95D11CE7@xxxxxx
Quote:

> 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 spreadsheet 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
--


My System SpecsSystem Spec
Old 06-19-2009   #13 (permalink)
dave


 
 

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

Does this work if i name these as .vbs and double click them? i'm getting
errors when i do that?

"Richard Mueller [MVP]" wrote:
Quote:

>
> "dave" <dave@xxxxxx> wrote in message
> news63F1F90-9339-4C1E-9E86-841D95D11CE7@xxxxxx
Quote:

> > 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 spreadsheet 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
> --
>
>
>
My System SpecsSystem Spec
Old 06-20-2009   #14 (permalink)
Richard Mueller [MVP]


 
 

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

Sorry, I forgot to assign a value to variable strReport. This should be the
file name and path of the log file to be created by the program. For
example:

' Open output file to write results.
strReport = "c:\Scripts\report.txt"
Set objReport = objFSO.OpenTextFile(strReport, _
ForWriting, CreateIfNotExist, OpenAsASCII)

Note the additional statement that assigns the value to strReport. This
would apply to both programs I posted. The file name and path should be
modified for your situation. Also you should modifity the value of strFile
for your situation, the file that contains the computer names.

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

"dave" <dave@xxxxxx> wrote in message
news:005A3491-F624-4359-AB36-D43BC1FEA006@xxxxxx
Quote:

> Does this work if i name these as .vbs and double click them? i'm getting
> errors when i do that?
>
> "Richard Mueller [MVP]" wrote:
>
Quote:

>>
>> "dave" <dave@xxxxxx> wrote in message
>> news63F1F90-9339-4C1E-9E86-841D95D11CE7@xxxxxx
Quote:

>> > 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 spreadsheet 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
>> --
>>
>>
>>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
retrive all AD groups and its members VB Script
Exporting full list of members of a group (including groups andexternal accounts), but filtered and sorted VB Script
How to create a list with all distrubtion groups and it's members PowerShell
VBS reading all groups from OU and there members VB Script
Contact Groups: Cannot Select Members Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46