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
Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
If you want to move up through the ranks in your technology career, talent and hard work are the bare necessities. But they aren’t enough to make you stand out. Expanding your skills, actively promoting your accomplishments and using promotion st…
Notifications on Experts Exchange help you keep track of your activity and updates in one place. Watch this video to learn how to use them on the site to quickly access the content that matters to you.
Saved searches can save you time by quickly referencing commonly searched terms on any topic. Whether you are looking for questions you can answer or hoping to learn about a specific issue, a saved search can help you get the most out of your time o…

860 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