[windows2000] Re: Identifying and Removing Dead User Accounts from NT Domain

  • From: "Durbin, Jeff" <jdurbin@xxxxxxxxxxxxxxxxxxx>
  • To: <windows2000@xxxxxxxxxxxxx>
  • Date: Thu, 11 Sep 2003 18:38:41 -0700

Ask and you shall receive. Save the text below as a file with a VBS
extension. Double-click it. It will ask you for a domain name. Tell it
the domain name, and it will produce a file called "LoginTimeLog.csv".
It's just a plain text file, but if you open it in Excel, you can select
all cells, then click Data, Sort, and use the second column. Then you'll
have a list of accounts and their last login times, sorted by login
time.
 
Jeff Durbin
 
 
 
Option Explicit
On Error Resume Next
Const ForReading = 1, ForWriting = 2, ForAppending = 8
 
  Dim strOut, strDomain
  strDomain = Inputbox("Domain to query?")
  if strDomain = "" then wscript.quit
  GetLastLoginTimesForDomainUsers strDomain
  CreateLogFile "LoginTimeLog.csv", strOut
  msgbox "Done." 
 
' ------------------
' END OF MAIN SCRIPT
' ------------------
 
Sub GetLastLoginTimesForDomainUsers(strDomainName)
  On Error Resume Next
  Dim oDomain, oUser, strLastLogin
 
  Set oDomain = GetObject("WinNT://" & strDomainName)
  oDomain.Filter = Array("User")
  For each oUser in oDomain
    strLastLogin = "Never"
    strLastLogin = oUser.LastLogin
    strOut = strOut & oUser.Name & "," & strLastLogin & vbCRLF
  Next
End Sub
 
Sub CreateLogFile(strFileName,strDataToWrite)
  Dim oFS, oFile
  Set oFS = CreateObject("Scripting.FileSystemObject")
  Set oFile = oFS.OpenTextFile(strFileName, ForWriting, True)
  oFile.Write strDataToWrite
  set oFile = nothing
  set oFS = nothing
End Sub
 
 

        -----Original Message-----
        From: windows2000-bounce@xxxxxxxxxxxxx
[mailto:windows2000-bounce@xxxxxxxxxxxxx] On Behalf Of Ibrahim Abdi,
Mustafa
        Sent: Thursday, September 11, 2003 6:27 AM
        To: 'windows2000@xxxxxxxxxxxxx'
        Subject: [windows2000] Identifying and Removing Dead User
Accounts from NT Domain
        
        


        Hi all, 

        I am running an NT domain here with approx 500 users altogether
in this site. We are planning to move over to AD soon as part of our
preparation I would like to scan my NT4 PDC for dead user accounts so I
can remove them all prior to migration so my new Ad will only contain
active user accounts instead of loads of unused or disabled accounts
from people that may not be here anymore. So my question is: Is there a
resource kit Util or script or anything out there that will scan my
master SAM file or the user accounts on the PDC and tell me which
accounts have not been used for sometime and stuff?

        Any feedback appreciated. Many thanks in advance 

        Mustafa 

Other related posts: