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 - How to save output of echo to a file or omit using echo and save it

Reply
 
Old 10-08-2008   #1 (permalink)
Ruok


 
 

How to save output of echo to a file or omit using echo and save it

Hi,

I have found a lot of scripts that display messages on the screen, but
I failed to find one that would save it instead (effectively we should
get rid of echo command completely, I assume). I don't want to use
"cScript" command to invoke my script as it's not practical in many
cases. Can anyone help. Example:

-------------------
On Error Resume Next

Set objGroup = GetObject _
("LDAP://cn=Administrators,CN=BuiltIn,...,dc=uk")
objGroup.GetInfo

arrMemberOf = objGroup.GetEx("member")

WScript.Echo "Members:"
For Each strMember in arrMemberOf
WScript.echo strMember
Next
---------------------

Thanks a lot.

Kamil

My System SpecsSystem Spec
Old 10-08-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: How to save output of echo to a file or omit using echo and save it

Kamil wrote:
Quote:

>
> I have found a lot of scripts that display messages on the screen, but
> I failed to find one that would save it instead (effectively we should
> get rid of echo command completely, I assume). I don't want to use
> "cScript" command to invoke my script as it's not practical in many
> cases. Can anyone help. Example:
>
> -------------------
> On Error Resume Next
>
> Set objGroup = GetObject _
> ("LDAP://cn=Administrators,CN=BuiltIn,...,dc=uk")
> objGroup.GetInfo
>
> arrMemberOf = objGroup.GetEx("member")
>
> WScript.Echo "Members:"
> For Each strMember in arrMemberOf
> WScript.echo strMember
> Next
> ---------------------
>
The easiest way is to run the script at a command prompt with cscript and
redirect the output to a text file. Otherwise you can use the
FileSystemObject to write the output to a text file. For example:
=========
Option Explicit

Dim objGroup, objFSO, strFile, objFile
Dim arrMembers, strMember

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

' Specify output file.
strFile = "c:\scripts\report.txt"

' Open the file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, _
ForWriting, CreateIfNotExist, OpenAsASCII)

' Bind to the group object.
Set objGroup =
GetObject("LDAP://cn=Administrators,cn=BuiltIn,dc=MyDomain,dc=com")
' Retrieve member attribute.
' Trap error if there are no members.
On Error Resume Next
arrMembers = objGroup.GetEx("member")
If (Err.Number = 0) Then
On Error GoTo 0
' Enumerate members and write to file.
For Each strMember In arrMembers
obFile.WriteLine strMember
Next
End If
On Error GoTo 0

' Clean up.
objFile.Close

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


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Echo results of script to file PowerShell
echo output PowerShell
No file open,save, save as Vista General
What echo has do with Return value? PowerShell
Any Way To Get Rid Of The Echo? Vista music pictures video


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