Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

output data to a file

Posted on 2011-09-27
2
Medium Priority
?
243 Views
Last Modified: 2012-05-12
I am trying to save the out put of this script to a text file but its displaying to the screen. I tried to modify the echo statements but its not working after i modify this. Can someone help me here is what I have. I am wondering what am I doing wrong.


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("c:\output.txt", True)
On Error Resume Next
 
Const ADS_SCOPE_SUBTREE = 2
 
dtmCreationDate = "20110909000000.0Z"
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
 
objCommand.CommandText = _
    "SELECT Name, objectCategory, whenCreated FROM 'LDAP://cn=computers,dc=somedomain,dc=local' WHERE "  & _
        "whenCreated>='" & dtmCreationDate & "'"
Set objRecordSet = objCommand.Execute
 
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value
    Wscript.Echo objRecordSet.Fields("objectCategory").Value
    Wscript.Echo objRecordSet.Fields("whenCreated").Value
    objRecordSet.MoveNext
Loop
0
Comment
Question by:techdrive
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 36713621
Hi, one way to do it is to run
cscript YourScript.vbs > Output.txt

Regards,

Rob.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 36713626
The other way using the FSO is to change WScript.Echo statements to objFile.WriteLine

Regards,

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("c:\output.txt", True)
On Error Resume Next
 
Const ADS_SCOPE_SUBTREE = 2
 
dtmCreationDate = "20110909000000.0Z"
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
 
objCommand.CommandText = _
    "SELECT Name, objectCategory, whenCreated FROM 'LDAP://cn=computers,dc=somedomain,dc=local' WHERE "  & _
        "whenCreated>='" & dtmCreationDate & "'"
Set objRecordSet = objCommand.Execute
 
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    objFile.WriteLine objRecordSet.Fields("Name").Value
    objFile.WriteLine objRecordSet.Fields("objectCategory").Value
    objFile.WriteLine objRecordSet.Fields("whenCreated").Value
    objRecordSet.MoveNext
Loop

objFile.Close

Open in new window

0

Featured Post

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonstā€¦
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question