Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
One of the biggest challenges facing freelancers is balancing multiple projects and deadlines. Organizational skills and time management are key to keeping up with projects and staying on track. Luckily, we’ve curated seven tools to help you focus o…
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…

863 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

22 Experts available now in Live!

Get 1:1 Help Now