473,324 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Last Logon VB Script

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)(lastLogonTimeStam p<=" &
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
================================================== ===================

Nov 6 '07 #1
1 9155
On Nov 6, 9:07 am, RC <RichJChri...@gmail.comwrote:
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)(lastLogonTimeStam p<=" &
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

Nov 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cwnewbe1 | last post by:
I would like to be able to add environment symbols to the Microsoft XP registry. I tried the example in the Python Cookbook by Orielly by running the script locally and it worked fine. Although I...
1
by: Newbie | last post by:
I have set up an ASP script (with some help from microsoft.public.inetserver.asp.general!) that grabs the windows username of the user and puts it into an Access database. It is setup on IIS5 as a...
2
by: W Akthar | last post by:
Hi All, I have written a windows service which runs a small windows application. This windows application queries a sql server database and depending on these results, sets appointments in...
2
by: Rune Amundsen | last post by:
Is it possible to run logon without using asp-script? I use plain HTML. Everyone that will log in will use no username, everyone will use the same password, so I don't need a database of usernames...
5
by: Peter Newman | last post by:
Im still struggling to get this executing a stored proc working .. im running vb.net (2003) and SQL 2005.. the story thus far is with a lot of help and a prevailing wind i have come up with the...
0
by: robpimentel | last post by:
Hi, I've been using DB2 for about 1 week, so please bear with me. DB2 Connect Enterprise Edition v8.1 FixPack 5 Windows Server 2003 Standard Edition SP1 Here is an error that continues to...
2
by: rodentboy | last post by:
I am trying to write a logon script in windows 2000 group policy that will archive the users .pst files to a share on the network. We already have a general.bat logon script that maps to the users...
1
by: Erenst | last post by:
Can any one tell me if SQL stores the last logon dat for a user and where. I would like to pull reports re users last logings to the server and then database.
0
by: Nomad50 | last post by:
I have SQL 2005 running on a server 2003 computer (Docro-Svr2) and a server 2000 computer (Docro-Svr1) running our Intranet site using IIS ver 5. I am using a DSN-less connection from an ASP script...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.