Last Logon VB Script

R

RC

How easy would it be for me to send the result from this script to a
txt or csv file. I also want to make sure it is getting the results
from all Domain Controllers in the domain. The LLTS may vary depending
on which DC the user authenticated with. (all thought I believe
Microsoft shorted the time that it takes to replicate that data to all
dc's down to 7days in windows 2003 server)

=====================================================================
FindOldComputers(90)

WScript.Echo
strDate = GetDate(strDaysOld)

strLDAP = "(&(objectCategory=computer)(lastLogonTimeStamp<=" &
strDate & "))"

set oRootDSE = GetObject("LDAP://RootDSE")
strDomainNC = oRootDSE.Get("defaultNamingContext")
set oRootDSE = Nothing

Set oConnection = CreateObject("ADODB.Connection")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider"

Set oCommand = CreateObject("ADODB.Command")
Set oCommand.ActiveConnection = oConnection

strQuery = "<LDAP://"& strDomainNC &">;" & strLDAP &
";AdsPath;subtree"

oCommand.CommandText = strQuery
oCommand.Properties("Page Size") = 1000

Set oRecordSet = oCommand.Execute

if not oRecordSet.Eof Then
WScript.Echo "- Object Count: " & oRecordSet.RecordCount
While Not oRecordSet.Eof
Set x =
GetObject(oRecordSet.Fields("AdsPath").Value)
strTimeStamp = GetLastLogonDate(x.distinguishedName)
WScript.Echo x.name & " - " & strTimeStamp
oRecordSet.MoveNext
Wend
end If

End Sub

'Returns number of 100 nano second intervals starting from 00:00
1/1/1601 minus the days provided.
Function GetDate(strDaysOld)
On Error Resume next
dtmDate = DateAdd("d", -strDaysOld, Now())
dbl100NanoSecs = 10000000 * (DateDiff("s", "1/1/1601", dtmDate))
dbl100NanoSecs = FormatNumber(dbl100NanoSecs, 0, False, False ,
0)
GetDate = dbl100NanoSecs
End Function

'Returns last logon date of provided computer
Function GetLastLogonDate(strCompDN)
'On Error Resume next
set objComp = GetObject("LDAP://" & strCompDN)
set objLogon = objComp.Get("lastLogonTimestamp")
intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
intLogonTime = intLogonTime / (60 * 10000000)
intLogonTime = intLogonTime / 1440
GetLastLogonDate = intLogonTime + #1/1/1601#
End Function
=====================================================================
 
R

rowe_newsgroups

How easy would it be for me to send the result from this script to a
txt or csv file. I also want to make sure it is getting the results
from all Domain Controllers in the domain. The LLTS may vary depending
on which DC the user authenticated with. (all thought I believe
Microsoft shorted the time that it takes to replicate that data to all
dc's down to 7days in windows 2003 server)

=====================================================================
FindOldComputers(90)

WScript.Echo
strDate = GetDate(strDaysOld)

strLDAP = "(&(objectCategory=computer)(lastLogonTimeStamp<=" &
strDate & "))"

set oRootDSE = GetObject("LDAP://RootDSE")
strDomainNC = oRootDSE.Get("defaultNamingContext")
set oRootDSE = Nothing

Set oConnection = CreateObject("ADODB.Connection")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider"

Set oCommand = CreateObject("ADODB.Command")
Set oCommand.ActiveConnection = oConnection

strQuery = "<LDAP://"& strDomainNC &">;" & strLDAP &
";AdsPath;subtree"

oCommand.CommandText = strQuery
oCommand.Properties("Page Size") = 1000

Set oRecordSet = oCommand.Execute

if not oRecordSet.Eof Then
WScript.Echo "- Object Count: " & oRecordSet.RecordCount
While Not oRecordSet.Eof
Set x =
GetObject(oRecordSet.Fields("AdsPath").Value)
strTimeStamp = GetLastLogonDate(x.distinguishedName)
WScript.Echo x.name & " - " & strTimeStamp
oRecordSet.MoveNext
Wend
end If

End Sub

'Returns number of 100 nano second intervals starting from 00:00
1/1/1601 minus the days provided.
Function GetDate(strDaysOld)
On Error Resume next
dtmDate = DateAdd("d", -strDaysOld, Now())
dbl100NanoSecs = 10000000 * (DateDiff("s", "1/1/1601", dtmDate))
dbl100NanoSecs = FormatNumber(dbl100NanoSecs, 0, False, False ,
0)
GetDate = dbl100NanoSecs
End Function

'Returns last logon date of provided computer
Function GetLastLogonDate(strCompDN)
'On Error Resume next
set objComp = GetObject("LDAP://" & strCompDN)
set objLogon = objComp.Get("lastLogonTimestamp")
intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
intLogonTime = intLogonTime / (60 * 10000000)
intLogonTime = intLogonTime / 1440
GetLastLogonDate = intLogonTime + #1/1/1601#
End Function
=====================================================================

Wrong newsgroup. You need the one for VB Script, not Visual
Basic .Net.

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top