Link to home
Start Free TrialLog in
Avatar of TaliaI
TaliaI

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of wasiftoor
wasiftoor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TaliaI
TaliaI

ASKER

This was a very quick and easy way of getting the results I was looking for.