Question : create log from a cscript ran file

Guys

I am needing to run this script using CSCRIPT but need the results to be created in a log file

can anyone help

On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

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

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
    "SELECT Name FROM 'LDAP://dc=fabrikam,dc=com' WHERE objectCategory='computer'"  
Set objRecordSet = objCommand.Execute

Wscript.Echo objRecordSet.RecordCount


Cheers

Darren

Answer : create log from a cscript ran file

This will create the output file "ADComputerList.txt" in the same folder where the script is called from.  If you want a specific path, just enter the full path of the file.

'---------BEGIN
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const ADS_SCOPE_SUBTREE = 2

On Error Resume Next

Set fso = CreateObject("Scripting.FileSystemObject")
Set objResults = fso.CreateTextFile("ADComputerList.txt", ForWriting)

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

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
    "SELECT Name FROM 'LDAP://dc=fabrikam,dc=com' WHERE objectCategory='computer'"  
Set objRecordSet = objCommand.Execute

objResults.writeline objRecordSet.RecordCount


-TM
Random Solutions  
 
programming4us programming4us