Ever want to have a database of the last logons in your environment? Well, here is a little vbs script that will do just that!
Option Explicit
Const adOpenKeyset = 1
Const adLockOptimistic = 3
' LastLogon table in LastLogon database:
' user_account varchar 50
' lastDC varchar 50
' lastlogon_time datetime 8
' insert_time datetime 8
Dim sqlConn, sqlComm, sqlProvider, sqlRS
Dim user_account, lastDC, lastlogon_time, insert_time
sqlProvider = "Server=***servername***;Database=LastLogon;Trusted_Connection=yes;"
Set sqlConn = CreateObject("ADODB.Connection")
sqlConn.Provider = "sqloledb"
sqlConn.Open sqlProvider
Set sqlRS = CreateObject("ADODB.Recordset")
sqlRS.ActiveConnection = sqlConn
sqlRS.CursorType = adOpenKeyset
sqlRS.LockType = adLockOptimistic
sqlRS.Source = "SELECT DISTINCT user_account, lastDC, lastlogon_time, insert_Time " & _
"FROM LastLogon " & _
"ORDER BY user_account"
sqlRS.Open
While (Not sqlRS.EOF)
user_account = sqlRS.Fields("user_account")
lastDC = sqlRS.Fields("lastDC")
lastlogon_time = sqlRS.Fields("lastlogon_time")
insert_time = sqlRS.Fields("insert_time")
WScript.Echo user_account & " " & lastlogon_time & " " & lastDC
sqlRS.MoveNext
Wend
sqlRS.Close
sqlConn.Close
Friday, March 23, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment