Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: lastlogonTimeStamp Script... Works but...

HTVi
TV Discussion Newsgroups

lastlogonTimeStamp Script... Works but...
Chris <stealthyc[ at ]gmail.com> 6/13/2007 12:40:22 PM
Ok well here is my script. It works sort of... What I would like for
it to do it get the lastlogontimestamp for every user in the domain.
It works if I add - On Error Resume Next - putting this in either
skips the record that does not have a lastlogontimestamp or uses
outputs the same timestamp from the previous user account.

If I leave it out I get the following error - (33, 4) Active
Directory: The directory property cannot be found in the cache. -

Line (33, 4) is - set objLogon = objUser.Get("lastLogonTimeStamp")

I tried to add in this but I think I'm doing it wrong. Instead of
skipping or outputting the wrong timestamp I would like for it to say
- 404 TimeStamp Not Found - .... something along those lines :P

If Hex(Err.Number)="&H8000500D" Then
WScript.Echo "No such property!" & vbCrLf & "Err. Number: " _
& vbTab & CStr(Hex(Err.Number)) & vbCrLf & "Err. Descr.: " _
& vbTab & Err.Description
End If

==========================


Any suggestions?

Thank You

============================

On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2

Dim objRootDSE
Dim objConnection, objCommand, objRecordSet
Dim UserDN, objUser, strDNSDomain, strQuery
Dim objLogon, strWeeks, strDays, intLogonTime
Dim intLLTS, intReqCompare, ADVersion

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

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

strQuery = "SELECT distinguishedName FROM 'LDAP://" & strDNSDomain &
"' WHERE objectCategory = 'User'"

objCommand.CommandText = strQuery
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
UserDN = objRecordSet.Fields("distinguishedName").Value
Set objUser = GetObject("LDAP://" & UserDN)
wscript.echo UserDN
' Begin calculation
set objLogon = objUser.Get("lastLogonTimeStamp")
intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
intLogonTime = intLogonTime / (60 * 10000000)
intLogonTime = intLogonTime / 1440
intLLTS = intLogonTime + #1/1/1601#
strDays = strWeeks * 7
intReqCompare = Now - strDays
If intLLTS < intReqCompare Then
wscript.echo Mid(objUser.Name,4) & " last logged on
at " & intLLTS
End If
objRecordSet.MoveNext
Loop

Re: lastlogonTimeStamp Script... Works but...
"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> 6/13/2007 1:52:38 PM
See my reply in microsoft.public.scripting.vbscript

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"Chris" <stealthyc[ at ]gmail.com> wrote in message
news:1181738422.984241.269980[ at ]o11g2000prd.googlegroups.com...
[Quoted Text]
> Ok well here is my script. It works sort of... What I would like for
> it to do it get the lastlogontimestamp for every user in the domain.
> It works if I add - On Error Resume Next - putting this in either
> skips the record that does not have a lastlogontimestamp or uses
> outputs the same timestamp from the previous user account.
>
> If I leave it out I get the following error - (33, 4) Active
> Directory: The directory property cannot be found in the cache. -
>
> Line (33, 4) is - set objLogon = objUser.Get("lastLogonTimeStamp")
>
> I tried to add in this but I think I'm doing it wrong. Instead of
> skipping or outputting the wrong timestamp I would like for it to say
> - 404 TimeStamp Not Found - .... something along those lines :P
>
> If Hex(Err.Number)="&H8000500D" Then
> WScript.Echo "No such property!" & vbCrLf & "Err. Number: " _
> & vbTab & CStr(Hex(Err.Number)) & vbCrLf & "Err. Descr.: " _
> & vbTab & Err.Description
> End If
>
> ==========================
>
>
> Any suggestions?
>
> Thank You
>
> ============================
>
> On Error Resume Next
> Const ADS_SCOPE_SUBTREE = 2
>
> Dim objRootDSE
> Dim objConnection, objCommand, objRecordSet
> Dim UserDN, objUser, strDNSDomain, strQuery
> Dim objLogon, strWeeks, strDays, intLogonTime
> Dim intLLTS, intReqCompare, ADVersion
>
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDNSDomain = objRootDSE.Get("defaultNamingContext")
>
> 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
>
> strQuery = "SELECT distinguishedName FROM 'LDAP://" & strDNSDomain &
> "' WHERE objectCategory = 'User'"
>
> objCommand.CommandText = strQuery
> Set objRecordSet = objCommand.Execute
>
> objRecordSet.MoveFirst
> Do Until objRecordSet.EOF
> UserDN = objRecordSet.Fields("distinguishedName").Value
> Set objUser = GetObject("LDAP://" & UserDN)
> wscript.echo UserDN
> ' Begin calculation
> set objLogon = objUser.Get("lastLogonTimeStamp")
> intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
> intLogonTime = intLogonTime / (60 * 10000000)
> intLogonTime = intLogonTime / 1440
> intLLTS = intLogonTime + #1/1/1601#
> strDays = strWeeks * 7
> intReqCompare = Now - strDays
> If intLLTS < intReqCompare Then
> wscript.echo Mid(objUser.Name,4) & " last logged on
> at " & intLLTS
> End If
> objRecordSet.MoveNext
> Loop
>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen