When I run net user , I get the great screen of information. One of of the items Last Logon would be great to see in a report. I've tried all the powershell and vbs scripts I can find, but they all seem to require Active Directory. I'm looking for a batch file that will create a report listing the last logon for all my users.
Asked
Active
Viewed 805 times
1 Answers
0
@if (@This==@IsBatch) @then
@echo off
rem **** batch zone *********************************************************
setlocal enableextensions disabledelayedexpansion
cscript //nologo //E:JScript "%~f0"
rem End of batch area. Ensure batch ends execution before reaching
rem javascript zone
exit /b
@end
// **** Javascript zone *****************************************************
var dict = new ActiveXObject("Scripting.Dictionary");
dict.Add("u","user");
var computer=GetObject("WinNT://.");
computer.Filter = dict.Items();
for (var users = new Enumerator(computer) ;!users.atEnd();users.moveNext()){
var user=users.item();
try { var lastLogin = user.LastLogin; } catch (e) { lastLogin='never' };
WScript.StdOut.WriteLine(user.Name+'='+lastLogin);
}

MC ND
- 69,615
- 8
- 84
- 126
-
How can i send this to a csv or text file – Kevin Baker Oct 08 '14 at 17:24
-
@KevinBaker, `getLastLogon.cmd > file.txt` – MC ND Oct 08 '14 at 19:48