?
Solved

output data to a file

Posted on 2011-09-27
2
Medium Priority
?
240 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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.
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

770 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