Last login time in AD

Does anyone knw of a tool to extract the last login time for all my user accounts in AD?

I’m trying to establish which old service accounts I can remove to neaten up the joint.

this should get you some of the way there,

Set WSHNetwork = WScript.CreateObject("WScript.Network")
Dim struser, objdomain, objcomputer
Dim fso, MyFile, target_File

Set objdomain = GetObject("WinNT://*****domain name*****t")
Set fso = CreateObject("Scripting.FileSystemObject")
struser = inputbox("Please type in the users logon","Logon", "logon")

Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")
Set wshell = wscript.createobject("")

desktop = wshell.specialfolders("desktop")
target_File = desktop & "\user_details.txt"

Set UserObj = GetObject("WinNT://connet/" & strUser ) 
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(TextF, True) 

	open_File.Writeline UserObj.fullname
	open_File.Writeline UserObj.description
	open_File.Writeline UserObj.LoginScript
	open_File.Writeline UserObj.accountdisabled
	open_File.Writeline UserObj.IsAccountLocked
	open_File.Writeline UserObj.homedirectory
	open_File.Writeline UserObj.profile
	open_File.Writeline UserObj.LastLogin
	open_File.Writeline UserObj.PasswordExpirationDate

Set UserObj = Nothing 

Function Open_My_File_Write()
	If (fsoObject.FileExists(target_File)) Then
		Set open_File = fsoObject.OpenTextFile(target_File, 8)
		'msgbox "file exists"
		Set open_File = fsoObject.OpenTextFile(target_File, 2, "True")
		'msgbox "file not exist"
	End If
End Function

Function Close_My_File()
End Function

you could have it scan all user accounts for a date outside of a specific range.

though this may be more usefull, but it is untried as I have no domain to try it on here :slight_smile:

Option Explicit 
On Error Resume Next 
Dim FileSys, WrLines, DomainName, oDomain, oDomainItem 

DomainName = InputBox("Please Enter Your Fully Qualified NT Domain Name", "Input", "") 
lastdate = InputBox("Please Enter a date", "Input", "20/06/2006") 

Set FileSys = CreateObject("Scripting.FileSystemObject") 
Set WrLines = FileSys.CreateTextFile("old-users.csv", True) 

WrLines.WriteLine("Logon Name,Last login,Full Name") 

Set oDomain = GetObject("WinNT://" & DomainName) 
   For Each oDomainItem in oDomain 
      If oDomainItem.Class = "User" AND oDomainItem.LastLogin > lastdate Then 
         WrLines.WriteLine(oDomainItem.Name & "," & oDomainItem.LastLogin & "," & oDomainItem.FullName) 
      End If 

WScript.Echo "Done" 

Thanks Dammo, i’ll give it a go.