Solved

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

Posted on 2012-04-04
2
139 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 500 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This is a quick article, and by no means should you quit your job today or plan to feed your family of 5 on a business idea. Starting a business takes work. This article will only give you the basic skeleton of understanding. Going into business for…
EE introduced a new rating method known as Level, which displays in your avatar as LVL. The new Level is a numeric ranking that is based on your Points. This article discusses the rationale behind the new method and provides the mathematical formula…
Articles on a wide range of technology and professional topics are available on Experts Exchange. These resources are written by members, for members, and can be written about any topic you feel passionate about. Learn how to best write an article t…
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.

708 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

16 Experts available now in Live!

Get 1:1 Help Now