Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Modify .vbs script to send information to output file not screen

Posted on 2012-04-04
2
Medium Priority
?
168 Views
Last Modified: 2012-07-12
I need this script below to run without popping up on the screen but creating an output file with the information in it.



arrAttributes = Array("homeDirectory","displayname","mail")  

Set adoCommand = CreateObject("ADODB.Command")  
Set adoConnection = CreateObject("ADODB.Connection")  
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection  

Set objRootDSE = GetObject("LDAP://RootDSE")  
strBase = "<LDAP://" & objRootDSE.Get("defaultNamingContext") & ">"
Set objRootDSE = Nothing

strFilter = "(&(objectCategory=person)(objectClass=user)(homeDirectory=*))"
strAttributes = Join(arrAttributes,",")  
Wscript.Echo Join(arrAttributes,";") & " ; home directory size in MB"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery  
adoCommand.Properties("Page Size") = 100  
adoCommand.Properties("Timeout") = 30  
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute  
Do Until adoRecordset.EOF  
    On Error Resume Next
    strTempOutput = "" 
    For i = 0 To Ubound(arrAttributes)  
        strTempOutput =  strTempOutput & " ; " & adoRecordset.Fields(arrAttributes(i)).Value  
        strOutput = Mid(Ltrim(strTempOutput),3)  
   Next
   Wscript.Echo strOutput & " ; " & Foldersize (adoRecordset.Fields(arrAttributes(0)).Value) & " MB"
    adoRecordset.MoveNext  
Loop

adoRecordset.Close  
adoConnection.Close  
Set adoRecordset = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing

Function Foldersize(strPath)  
   On Error Resume Next
   Set objNetwork = CreateObject("WScript.Network")  
   Set objFSO = CreateObject("scripting.filesystemobject")  
   objNetwork.MapNetworkDrive "p:", strPath  
   Set objFld = objFSO.GetFolder("p:")  
   Foldersize = Round(objFld.Size/1048576,2)  
   objNetwork.RemoveNetworkDrive "p:"
   Set objFld = Nothing
   Set objFSO = Nothing
End Function
0
Comment
Question by:TaliaI
2 Comments
 
LVL 9

Accepted Solution

by:
wasiftoor earned 2000 total points
ID: 37808714
The best solution is not to modify the script at all and just use the ">>" Command Shell Redirection commands to output (append) all Echo statement results to a file on the specified location.

If HelloWorld.vbs  is your script than you can execute that as:

cscript HelloWorld.vbs >> C:\users\AnyUser\Desktop\output.txt

This will generate a new file output.txt on AnyUser's Desktop with the results from the Echo Statements.
0
 

Author Closing Comment

by:TaliaI
ID: 38180510
This was a very quick and easy way of getting the results I was looking for.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This story has been written with permission from the scammed victim, a valued client of mine – identity protected by request.
This article is written by John Gates, CISSP. Gates, the SNUG President-Elect, currently holds the position of Manager of Information Systems at Lake Park High School in Roselle, Illinois.
The Bounty Board allows you to request an article or video on any technical topic, or fulfill a bounty request to earn points. Watch this video to learn how to use the Bounty Board to get the content you want, earn points, and browse submitted bount…
Where to go on the main page to find the job listings. How to apply to a job that you are interested in from the list that is featured on our Careers page.
Suggested Courses

810 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