Jump to content

Recommended Posts

Posted

I have this Windows Script and would like to output it to a text file. Can someone show me how that's done please?

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=btcbahamas,dc=com' WHERE objectCategory='user' " & _
"AND msNPAllowDialin = TRUE"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop


Posted

This will make a text file called Text_Report.txt in the folder where the script is.

Const ADS_SCOPE_SUBTREE = 2

Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")

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=btcbahamas,dc=com' WHERE objectCategory='user' " & _
"AND msNPAllowDialin = TRUE"
Set objRecordSet = objCommand.Execute

Dim Ts

Set Ts = Fso.CreateTextFile("Text_Report.txt")

Ts.WriteLine Now

objRecordSet.MoveFirst

Do Until objRecordSet.EOF

Ts.WriteLine objRecordSet.Fields("Name").Value

Wscript.Echo objRecordSet.Fields("Name").Value

objRecordSet.MoveNext
Loop
Ts.Close

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...