-4

This script gets remote user's membership info and saves a report.txt as a result. Can this code be changed with wscript.echo in place of Report.txt. I tried to change it but i couldnt :( Thank you in advance

 strUsers = InputBox("Enter Username: ")
 arrUsers = Split(strUsers, ",")

 If strUsers <> "" Then
 On Error Resume Next
 Err.Clear

 '("WScript.Network")
 Set fs = CreateObject ("Scripting.FileSystemObject")
 Set outFile = fs.CreateTextFile (".\Report.txt")

outFile.WriteLine "Active User's Membership"
For x = 0 to UBound(arrUsers)
arrUsers(x) = Trim(arrUsers(x))
If x = 0 Then
    'outFile.WriteLine "USER: " & arrUsers(x)
Else
    outFile.WriteLine "        " & arrUsers(x)
End If
Next 
outFile.WriteLine "==========="
For x = 0 to UBound(arrUsers)
Call getGroups(arrUsers(x))
Next

Wscript.echo "Check the Report (report.txt) File!"


Sub getGroups(strUser)
Set oNetwork = CreateObject("WScript.Network")
strDomain = oNetwork.UserDomain
On Error Resume Next
Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
If Err.Number <> 0 Then
    outFile.WriteLine strUser & " not found..."
    Exit Sub
End If
Err.Clear
On Error Goto 0

outFile.WriteLine strUser & " - " & oUser.FullName

For Each strGroup In oUser.Groups
    outFile.WriteLine "" & strGroup.Name
Next
End Sub

ElseIf strUsers = "" Then
WScript.Echo "Cancelled."
End If
serdar
  • 127
  • 7

2 Answers2

1

If I'm understanding you right, you just want this script to output to screen instead of the text file which is easy enough to do. Not sure what problems you were having or what you tried..

Remove these lines:

'("WScript.Network")
Set fs = CreateObject ("Scripting.FileSystemObject")
Set outFile = fs.CreateTextFile (".\Report.txt")
.
.
.
Wscript.echo "Check the Report (report.txt) File!"

and replace any instance of outFile.WriteLine with wscript.echo

Rex
  • 7,895
  • 3
  • 29
  • 45
  • Rex, I made what you said; but the script didnt work.. :( It also didnt give any error... – serdar Sep 19 '14 at 07:44
  • @serdar You did what I said but the script didn't work but then posted the end result of my instructions as the answer that worked? Really? – Rex Sep 25 '14 at 18:45
-1

WORKING SCRIPT :) IS THIS

strUsers = InputBox("Enter Username: ")
arrUsers = Split(strUsers, ",")

If strUsers <> "" Then
On Error Resume Next
Err.Clear

WScript.Echo "Active User's Membership"
For x = 0 to UBound(arrUsers)
arrUsers(x) = Trim(arrUsers(x))
If x = 0 Then
    'outFile.WriteLine "USER: " & arrUsers(x)
Else
    WScript.Echo "        " & arrUsers(x)
End If
Next 
WScript.Echo "==========="
For x = 0 to UBound(arrUsers)
Call getGroups(arrUsers(x))
Next

WScript.Echo "Check the Report (report.txt) File!"


Sub getGroups(strUser)
Set oNetwork = CreateObject("WScript.Network")
strDomain = oNetwork.UserDomain
On Error Resume Next
Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
If Err.Number <> 0 Then
    WScript.Echo strUser & " not found..."
    Exit Sub
End If
Err.Clear
On Error Goto 0

WScript.Echo strUser & " - " & oUser.FullName

For Each strGroup In oUser.Groups
    WScript.Echo "" & strGroup.Name
Next
End Sub

ElseIf strUsers = "" Then
WScript.Echo "Cancelled."
End If
serdar
  • 127
  • 7