getBesUsers.vbs
'Setup our objects
Set ConWSH=WScript.CreateObject("ADODB.Connection")
'Define our connection string
'strConnection = "Driver={SQL Server};Server=servername;User ID=userid;Password=password;Database=BESMgmt;"
strConnection = "Provider=SQLOLEDB;Data Source=blackberry5db;Initial Catalog=BESMgmt;Network=DBMSSOCN;Trusted_Connection=Yes;"
'and parameters
with ConWSH
.ConnectionString=strConnection
.ConnectionTimeout=25
.CommandTimeout=25
.Open
end with
'See what we're supposed to grab
'strSearchTest = InputBox ("Search For:", "Who said that anyway?", "Enter Some Text")
'define our SQL statement
' example: strSQL = "SELECT Column1, Column2 FROM tblTABLENAME WHERE Column1 like '%" & strSearchTest & "%'"
strSQL = "SELECT MailboxDN FROM UserConfig"
'Run the SQL statement
set rs=createobject("ADODB.Recordset")
with rs
.activeconnection=ConWSH
.CursorType=adOpenForwardOnly
.CursorLocation=3
.open strSQL
end with
'OK we've got a recordset to deal with. Let's run through it
'Check if it's empty or not
if rs.recordcount = 0 then
'Check if it's empty or not
Wscrip.Echo "No records found. Exiting."
'Exit with errorlevel 9. If we're called from a batch file this will indicate
'completion status/type so we can branch off to another handler if needed.
wScript.Quit(9)
else
'Recordset was not empty.
intrsCounter = 0
do while not rs.eof
strOutput=trim (rs.fields("MailboxDN")) '& vbNewLine & trim(rs.fields("Column2"))
'msgbox strOutput
Wscript.Echo strOutput
rs.movenext
loop
end if
'Wscript.Echo "End of matching records."
'Clean up after ourselves, even though in WSH we don't really have to if the script ends here.
rs.close
set rs=nothing
ConWSH.close
set ConWSH=nothing