Solved

output data to a file

Posted on 2011-09-27
2
234 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
  • 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 500 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now