?
Solved

Starting with USRSTAT where M$ Left Off -- Script to put this all together?

Posted on 2003-03-30
7
Medium Priority
?
416 Views
Last Modified: 2013-12-28
My problem surronds the fact that the "Last Logon" information for user accounts doesn't replicate, and since some of my BDCs go down from time to time a single user may have conflicting last logon information on several BDCs or the PDC.

I've been using USRSTAT from the ResKit to gather the 'last logon' information from my PDC and a dozen or so BDCs.  Then I would take that information and compare it against each other in Excel or Access to determine the "actual" last logon.  Then I would sort that down to "60-90 Days since last logn", "90-120 days since last logon", & "120 & Over".

I've got to believe that this process can be scripted or programmed to be rolled together as one.  My budget $0.00 so I'm hoping that one of you has faced the challenge of weeding out old accounts in the past and has some script advice???

How can we automate the process of consolidating those lists from the PDC, & BDCs then parsing it out into 60-90, 90-120, 120&Over?

Points will be given for a complete solution, since I don't have any $ I can't buy a commercial product.

THANKS!
0
Comment
Question by:Skip_Anstey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 

Author Comment

by:Skip_Anstey
ID: 8234264
Increased Points
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 8315802
Have a try with the following script.
It uses usrstat.exe, removes conflicting entries, and creates four output files:
lodump-All.log (to be precise: <whatever-you-decide-to-name-the-command-file>-All.log), with all logon dates, lodump-060.log, with all logon dates older than about (the date calculation is rather crude, but I figured if you're looking for logon dates that date back 4 months, one or two days wouldn't matter ...) 60 days; lodump-090.log and -120.log respectively. All of the files are created always (that is to say: if there's no entry, the file will be there, it will just have a size of zero). Old files will be overwritten without further warning. There are four ";"-separated entries in each line: logon date, logon time, username and servername.
Just change the date delimiter according to the one that's used in your system, and adjust the sequence the day, month and year is put into the variables.
And then there was the usual disclaimer: no warranties included, test it, use it at your own risk ...

====lodump.cmd====8<-----------------------------------
@echo off
setlocal
rem *** Split ages in days (use multiples of 30)
set Age01=060
set Age02=090
set Age03=120
rem *** Name of the output files:
set OutFileAll=%~n0-All.log
set OutFile01=%~n0-%Age01%.log
set OutFile02=%~n0-%Age02%.log
set OutFile03=%~n0-%Age03%.log
rem *** Date delimiter of "date /t" command:
set DateDelim=.
rem *** New date delim, for use in output files:
set NewDateDelim=-

rem *** XP omits (why, oh why ...) the day in "date /t":
set DateToken=2,3,4
ver | find "XP" && set DateToken=1,2,3

rem *** Adjust date sequence if necessary:
for /f "tokens=%DateToken% delims=%DateDelim% " %%a in ('date /t') do (
  set CurDay=%%a
  set CurMon=%%b
  set CurYear=%%c
)

rem *** Remove a possible leading zero:
if %CurMon:~0,1%==0 set CurMon=%CurMon:~1%
rem *** Calculate the split dates:
call :SplitDate %Age01% 01
call :SplitDate %Age02% 02
call :SplitDate %Age03% 03

set TempFile=%~dpn0.tmp
set OldUser=

if exist "%OutFileAll%" del "%OutFileAll%"
usrstat %UserDomain% >"%TempFile%"
for /f "tokens=1*" %%a in (%TempFile%) do (
  set User=%%a
  set Tail=%%b
  call :process
)
del "%TempFile%"

echo Removing conflicting entries ...
for /f "tokens=1-4 delims=;" %%a in ('sort /r "%OutFileAll%"') do (
  set User=%%a
  set Date=%%b
  set Time=%%c
  set Server=%%d
  call :Duplicate
)

echo Splitting according to age ...
if exist "%OutFileAll%" del "%OutFileAll%"
echo Dummy 1>NUL 2>"%OutFile01%"
echo Dummy 1>NUL 2>"%OutFile02%"
echo Dummy 1>NUL 2>"%OutFile03%"
for /f "tokens=1-4 delims=;" %%a in ('sort "%TempFile%"') do (
  set Date=%%a
  set Time=%%b
  set User=%%c
  set Server=%%d
  call :Split
)
del "%TempFile%"
goto leave

rem **********************************************************************
:SplitDate
set Age=%1
set i=%2
set Year=%CurYear%
:LZLoop
if %Age:~0,1%==0 (
  set Age=%Age:~1%
  goto LZLoop
)
set /a Mon = CurMon - (Age / 30)
if %Mon% LSS 1 (
  set /a Mon += 12
  set /a Year -= 1
)
if %Mon% LSS 10 set Mon=0%Mon%
set SplitDate%i%=%Year%%NewDateDelim%%Mon%%NewDateDelim%%CurDay%
goto :eof

rem **********************************************************************
:process
rem *** usrstat starts the beginning of the dump of a new DC with "Users on \\<somedc>"
if /i not %User%==Users goto ProcessUser

for /f "tokens=2 delims=\" %%a in ("%Tail%") do set Server=%%a
echo Processing logon info on %Server% ...
goto :eof

:ProcessUser
for /f "tokens=1* delims=:" %%a in ("%Tail%") do set LastLogon=%%b
for /f "tokens=1-5" %%a in ("%LastLogon%") do (
  set Day=%%a
  set Month=%%b
  set Date=%%c
  set Time=%%d
  set Year=%%e
)
if /i %Day%==Never (
  set Month=00
  set Date=00
  set Time=00:00:00
  set Year=0000
)
if /i %Month%==Jan set Month=01
if /i %Month%==Feb set Month=02
if /i %Month%==Mar set Month=03
if /i %Month%==Apr set Month=04
if /i %Month%==May set Month=05
if /i %Month%==Jun set Month=06
if /i %Month%==Jul set Month=07
if /i %Month%==Aug set Month=08
if /i %Month%==Sep set Month=09
if /i %Month%==Oct set Month=10
if /i %Month%==Nov set Month=11
if /i %Month%==Dec set Month=12
(echo %User%;%Year%%NewDateDelim%%Month%%NewDateDelim%%Date%;%Time%;%Server%)>>"%OutFileAll%"
goto :eof

rem **********************************************************************
:Duplicate
if /i "%User%"=="%OldUser%" goto :eof
set OldUser=%User%
(echo %Date%;%Time%;%User%;%Server%)>>"%TempFile%"
goto :eof

rem **********************************************************************
:Split
(echo %Date%;%Time%;%User%;%Server%)>>"%OutFileAll%"
if %Date% LSS %SplitDate03% (
  (echo %Date%;%Time%;%User%;%Server%)>>"%OutFile03%"
  goto :eof
)
if %Date% LSS %SplitDate02% (
  (echo %Date%;%Time%;%User%;%Server%)>>"%OutFile02%"
  goto :eof
)
if %Date% LSS %SplitDate01% (
  (echo %Date%;%Time%;%User%;%Server%)>>"%OutFile01%"
  goto :eof
)
goto :eof

:leave

====lodump.cmd====8<-----------------------------------
0
 

Expert Comment

by:choppa_eye
ID: 11885042
I hadn't responded because no one posted an answer that worked -- I since have purchased an off the shelf application to perform the job.

I expect my points refunded.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 11885190
And what exactly didn't work with the script?
0
 

Expert Comment

by:choppa_eye
ID: 11885711
Its been so long I dont' remember off the top of my head -- I'll see if I can find any notes on it in my emails.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Configuring Remote Assistance for use with SCCM
A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question