bsharath
asked on
Usernames last used
Hi,
How can i get all the last used dates from all the users in the domain.
I have many common users created and dout if they are being used so need to take a report and delete them if not used.
Regards
Sharath
How can i get all the last used dates from all the users in the domain.
I have many common users created and dout if they are being used so need to take a report and delete them if not used.
Regards
Sharath
Take a look at the 4th post http://www.minasi.com/forum/topic.asp?TOPIC_ID=3724&whichpage=2
Oops, that was for each computer.
Google has tons of links (I'm sure at least one of them are pointing here
http://www.google.com/search?hl=en&safe=active&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=JAh&q=script+to+retrieve+last+logon+date&btnG=Search
But to assist in narrowing down a selection
http://www.rlmueller.net/Last%20Logon.htm
Google has tons of links (I'm sure at least one of them are pointing here
http://www.google.com/search?hl=en&safe=active&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=JAh&q=script+to+retrieve+last+logon+date&btnG=Search
But to assist in narrowing down a selection
http://www.rlmueller.net/Last%20Logon.htm
ASKER
I get this error.
C:\>cscript Lastlogon.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
C:\Lastlogon.vbs(154, 1) Microsoft VBScript runtime error: Variable is undefined
: 'server1'
C:\>cscript Lastlogon.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
C:\Lastlogon.vbs(154, 1) Microsoft VBScript runtime error: Variable is undefined
: 'server1'
ASKER
This is onemore error.
C:\>cscript //nologo LastLogon.vbs
CN=Guest,OU=Former Colleagues,OU=User Accounts,OU=IND,OU=Countri es,DC=Deve lopmen
t,DC=Group,DC=co,DC=uk;Nev er
C:\LastLogon.vbs(78, 5) Microsoft VBScript runtime error: Object doesn't support
this property or method
I have tried many which are availabe on the net but gives me errors.
C:\>cscript //nologo LastLogon.vbs
CN=Guest,OU=Former Colleagues,OU=User Accounts,OU=IND,OU=Countri
t,DC=Group,DC=co,DC=uk;Nev
C:\LastLogon.vbs(78, 5) Microsoft VBScript runtime error: Object doesn't support
this property or method
I have tried many which are availabe on the net but gives me errors.
What script are you running?
"Variable undefined" more or less means that your using a variable that wasn't listed at the beginning of the script.(all those "Dim" statements at the beginning)
Did you alter the script at all? If so can you post it?
"Variable undefined" more or less means that your using a variable that wasn't listed at the beginning of the script.(all those "Dim" statements at the beginning)
Did you alter the script at all? If so can you post it?
ASKER
This is the script.
' LastLogonTimeStamp.vbs
' VBScript program to determine when each user in the domain last logged
' on. Domain must be at Windows Server 2003 Functional Level.
'
' -------------------------- ---------- ---------- ---------- ---------- ----
' Copyright (c) 2007 Richard L. Mueller
' Hilltop Lab web site - http://www.rlmueller.net
' Version 1.0 - March 24, 2007
'
' The lastLogonTimeStamp attribute is Integer8, a 64-bit number
' representing the date as the number of 100 nanosecond intervals since
' 12:00 am January 1, 1601. This value is converted to a date. The last
' logon date is in UTC (Coordinated Univeral Time). It must be adjusted
' by the Time Zone bias in the machine registry to convert to local
' time.
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided that
' you agree that the copyright owner above has no warranty, obligations,
' or liability for such use.
Option Explicit
Dim objRootDSE, adoConnection, adoCommand, strQuery
Dim adoRecordset, strDNSDomain, objShell, lngBiasKey
Dim lngBias, k, strDN, dtmDate, objDate, lngDate
Dim strBase, strFilter, strAttributes, lngHigh, lngLow
' Obtain local Time Zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shel l")
lngBiasKey = objShell.RegRead("HKLM\Sys tem\Curren tControlSe t\Control\ " _
& "TimeZoneInformation\Activ eTimeBias" )
If (UCase(TypeName(lngBiasKey )) = "LONG") Then
lngBias = lngBiasKey
ElseIf (UCase(TypeName(lngBiasKey )) = "VARIANT()") Then
lngBias = 0
For k = 0 To UBound(lngBiasKey)
lngBias = lngBias + (lngBiasKey(k) * 256^k)
Next
End If
Set objShell = Nothing
' Determine DNS domain from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE" )
strDNSDomain = objRootDSE.Get("defaultNam ingContext ")
Set objRootDSE = Nothing
' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Comman d")
Set adoConnection = CreateObject("ADODB.Connec tion")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnectio n = adoConnection
' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"
' Filter on all user objects.
strFilter = "(&(objectCategory=person) (objectCla ss=user))"
' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName,lastLog on"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Pag e Size") = 100
adoCommand.Properties("Tim eout") = 60
adoCommand.Properties("Cac he Results") = False
Set adoRecordset = adoCommand.Execute
' Enumerate resulting recordset.
Do Until adoRecordset.EOF
' Retrieve attribute values for the user.
strDN = adoRecordset.Fields("disti nguishedNa me").Value
lngDate = adoRecordset.Fields("lastL ogon").Val ue
' Convert Integer8 value to date/time in current time zone.
On Error Resume Next
Set objDate = lngDate
If (Err.Number <> 0) Then
On Error GoTo 0
dtmDate = #1/1/1601#
Else
On Error GoTo 0
lngHigh = objDate.HighPart
lngLow = objDate.LowPart
If (lngLow < 0) Then
lngHigh = lngHigh + 1
End If
If (lngHigh = 0) And (lngLow = 0 ) Then
dtmDate = #1/1/1601#
Else
dtmDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow)/600000000 - lngBias)/1440
End If
End If
' Display values for the user.
If (dtmDate = #1/1/1601#) Then
Wscript.Echo strDN & ";Never"
Else
Wscript.Echo strDN & ";" & dtmDate
End If
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
adoConnection.Close
Set adoConnection = Nothing
Set adoCommand = Nothing
Set adoRecordset = Nothing
Set objDate = Nothing
Is there any thing i need to change
' LastLogonTimeStamp.vbs
' VBScript program to determine when each user in the domain last logged
' on. Domain must be at Windows Server 2003 Functional Level.
'
' --------------------------
' Copyright (c) 2007 Richard L. Mueller
' Hilltop Lab web site - http://www.rlmueller.net
' Version 1.0 - March 24, 2007
'
' The lastLogonTimeStamp attribute is Integer8, a 64-bit number
' representing the date as the number of 100 nanosecond intervals since
' 12:00 am January 1, 1601. This value is converted to a date. The last
' logon date is in UTC (Coordinated Univeral Time). It must be adjusted
' by the Time Zone bias in the machine registry to convert to local
' time.
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided that
' you agree that the copyright owner above has no warranty, obligations,
' or liability for such use.
Option Explicit
Dim objRootDSE, adoConnection, adoCommand, strQuery
Dim adoRecordset, strDNSDomain, objShell, lngBiasKey
Dim lngBias, k, strDN, dtmDate, objDate, lngDate
Dim strBase, strFilter, strAttributes, lngHigh, lngLow
' Obtain local Time Zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shel
lngBiasKey = objShell.RegRead("HKLM\Sys
& "TimeZoneInformation\Activ
If (UCase(TypeName(lngBiasKey
lngBias = lngBiasKey
ElseIf (UCase(TypeName(lngBiasKey
lngBias = 0
For k = 0 To UBound(lngBiasKey)
lngBias = lngBias + (lngBiasKey(k) * 256^k)
Next
End If
Set objShell = Nothing
' Determine DNS domain from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE"
strDNSDomain = objRootDSE.Get("defaultNam
Set objRootDSE = Nothing
' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Comman
Set adoConnection = CreateObject("ADODB.Connec
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnectio
' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"
' Filter on all user objects.
strFilter = "(&(objectCategory=person)
' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName,lastLog
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Pag
adoCommand.Properties("Tim
adoCommand.Properties("Cac
Set adoRecordset = adoCommand.Execute
' Enumerate resulting recordset.
Do Until adoRecordset.EOF
' Retrieve attribute values for the user.
strDN = adoRecordset.Fields("disti
lngDate = adoRecordset.Fields("lastL
' Convert Integer8 value to date/time in current time zone.
On Error Resume Next
Set objDate = lngDate
If (Err.Number <> 0) Then
On Error GoTo 0
dtmDate = #1/1/1601#
Else
On Error GoTo 0
lngHigh = objDate.HighPart
lngLow = objDate.LowPart
If (lngLow < 0) Then
lngHigh = lngHigh + 1
End If
If (lngHigh = 0) And (lngLow = 0 ) Then
dtmDate = #1/1/1601#
Else
dtmDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow)/600000000 - lngBias)/1440
End If
End If
' Display values for the user.
If (dtmDate = #1/1/1601#) Then
Wscript.Echo strDN & ";Never"
Else
Wscript.Echo strDN & ";" & dtmDate
End If
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
adoConnection.Close
Set adoConnection = Nothing
Set adoCommand = Nothing
Set adoRecordset = Nothing
Set objDate = Nothing
Is there any thing i need to change
Click Start -> Run -> Cmd.exe
DSQuery * domainroot -filter "(&(objectCategory=Person) (objectCla ss=User)(s AMAccountN ame=*))" -attr distinguishedName lastLogon -limit 0
OR (save result in file)
DSQuery * domainroot -filter "(&(objectCategory=Person) (objectCla ss=User)(s AMAccountN ame=*))" -attr distinguishedName lastLogon -limit 0 >C:\Result.txt
OR (with time)
DSQuery * domainroot -filter "(&(objectCategory=Person) (objectCla ss=User)(s AMAccountN ame=*))" -attr distinguishedName lastLogon lastLogonTimestamp -limit 0 >C:\Result.txt
OR (Username)
DSQuery * domainroot -filter "(&(objectCategory=Person) (objectCla ss=User)(s AMAccountN ame=*))" -attr displayName lastLogon -limit 0 >C:\Result.txt
Check Result.txt file on C: drive root for output.
DSQuery * domainroot -filter "(&(objectCategory=Person)
OR (save result in file)
DSQuery * domainroot -filter "(&(objectCategory=Person)
OR (with time)
DSQuery * domainroot -filter "(&(objectCategory=Person)
OR (Username)
DSQuery * domainroot -filter "(&(objectCategory=Person)
Check Result.txt file on C: drive root for output.
ASKER
farhankazi
I get the lastlogon time as this
128231107305474400
Is there any way to get it to right format as dd/mm/yy
I get the lastlogon time as this
128231107305474400
Is there any way to get it to right format as dd/mm/yy
DumpSec, can also provide user last logged on information. On the menu bar choose Reports, Dump users as a table, choose LastLogonTime and add, then OK to generate report;
http://www.somarsoft.com/
http://www.somarsoft.com/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
farhankazi:
I get this.
-------------------------- -
Windows Script Host
-------------------------- -
Script: C:\Lastlogon.vbs
Line: 1
Char: 1
Error: Invalid character
Code: 800A0408
Source: Microsoft VBScript compilation error
-------------------------- -
OK
-------------------------- -
I get this.
--------------------------
Windows Script Host
--------------------------
Script: C:\Lastlogon.vbs
Line: 1
Char: 1
Error: Invalid character
Code: 800A0408
Source: Microsoft VBScript compilation error
--------------------------
OK
--------------------------
Did read the instructions? :)
:: * Copy and paste following script in notepad and save it with any name having .cmd extension.
NOT with extension VBS.
:: * Copy and paste following script in notepad and save it with any name having .cmd extension.
NOT with extension VBS.
ASKER
Sorry my mistake :)
No worries :) Thanks