Jump to content

W2K Active Directory - LASTLOGIN


Der letzte Beitrag zu diesem Thema ist mehr als 180 Tage alt. Bitte erstelle einen neuen Beitrag zu Deiner Anfrage!

Empfohlene Beiträge

Geschrieben

hallo AD-Freaks,

 

Suche ein Scriptchen in vbs oder c#,

welches in einer MultiDomain (15 DC's) alle Lastlogins

der User in ein csv-File schreibt.

 

Da das LastLogin-Attribut nicht repliziert wird,

müssen alle DC's durchsucht werden.

 

Bin auch für einen guten Link dankbar :wink2: .

 

 

sega2003

Geschrieben

Moin sega2003,

mit VBS gehts so...

 

Option Explicit 

Sub RecurseLDAP(ByVal p_sAdsPath, ByVal p_sDCName) 
    Dim oOBJ, oSHM, oCHD, oValue 

    Set oOBJ = GetObject(p_sAdsPath) 
    Set oSHM = GetObject(oOBJ.Schema) 
    Call oOBJ.GetInfo 

    On Error Resume Next 
    oValue = oOBJ.LastLogin 
    If Err.Number = 0 Then 
         Dim dCurrDate, dOldDate 
         dCurrDate = DateValue(oValue) 
         dCurrDate = CDate(Year(dCurrDate) & "-" & _
                           Month(dCurrDate) & "-" & _
                           Day(dCurrDate) & " " & _
                           TimeValue(oValue))
         If oDict.Exists(oOBJ.sAMAccountName) Then 
              dOldDate = oDict.Item(oOBJ.sAMAccountName)(2) 
              If DateDiff("s", dCurrDate, dtNow) < DateDiff("s", dOldDate, dtNow) Then 
                   oDict.Item(oOBJ.sAMAccountName) = Array(oOBJ.Class, oOBJ.cn, dCurrDate) 
              End If 
         Else 
              Call oDict.Add(oOBJ.sAMAccountName, Array(oOBJ.Class, oOBJ.cn, dCurrDate)) 
         End If 
    Else 
         Call Err.Clear 
    End If 
    On Error Goto 0 

    If oSHM.Container Then 
         For Each oCHD In oOBJ 
              Call RecurseLDAP(oCHD.AdsPath, p_sDCName) 
         Next 
    End If 
End Sub 



Sub FormatDict(ByVal p_sFile) 
    Dim oFSO, oTS, dDate 
    Dim arrKeys, nIndex, sYear 

    Set oFSO = CreateObject("Scripting.FileSystemObject") 
    Set oTS = oFSO.CreateTextFile(p_sFile, True, True) 

    Call oTS.WriteLine("Class" & vbTab & "Acount" & vbTab & "cn" & vbTab & "Date/Time") 
    arrKeys = oDict.Keys 
    For nIndex = 0 To oDict.Count - 1 
         dDate = DateValue(oDict.Item(arrKeys(nIndex))(2)) 
         sYear = Year(dDate) 
         If CLng(sYear) < 1970 Then sYear = "1970" 
         Call oTS.WriteLine(oDict.Item(arrKeys(nIndex))(0) & vbTab & _
                            arrKeys(nIndex) & vbTab & _
                            oDict.Item(arrKeys(nIndex))(1) & vbTab & _
                            sYear & "-" & _
                            Month(dDate) & "-" & _
                            Day(dDate) & " " & _
                            TimeValue(oDict.Item(arrKeys(nIndex))(2)))
    Next 


    Call oTS.Close 
End Sub 


If WScript.Arguments.Count < 3 Then 
    WScript.Echo "Usage: CheckLogin.vbs    []" 
    WScript.Echo 
    WScript.Echo "" & vbTab & "output filename" 
    WScript.Echo "" & vbTab & "AD site name (ex: dc=site,dc=company,dc=loc)" 
    WScript.Echo "" & vbTab & "domain controller name" 
    WScript.Echo "" & vbTab & "other domain controllers name" 
    WScript.Echo 
    WScript.Echo "Examples" 
    WScript.Echo "CheckLogin.vbs c:\output.txt dc=site,dc=company,dc=loc DC1" 
    WScript.Echo "CheckLogin.vbs c:\output.txt dc=site,dc=company,dc=loc DC1 DC2 DC3"
    WScript.Quit 
End If 

Dim dtNow, oDict, sFile, sSite, nDCIndex, sDCName 

dtNow = Now 
Set oDict = CreateObject("Scripting.Dictionary") 
sFile = WScript.Arguments(0) 
sSite = WScript.Arguments(1) 


For nDCIndex = 2 To WScript.Arguments.Count - 1 
    sDCName = WScript.Arguments(nDCIndex) 
    Call RecurseLDAP("LDAP://" & sDCName & "/" & sSite, sDCName) 
Next 
Call FormatDict(sFile)

 

thorgood

Der letzte Beitrag zu diesem Thema ist mehr als 180 Tage alt. Bitte erstelle einen neuen Beitrag zu Deiner Anfrage!

Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde dich hier an.

Jetzt anmelden
×
×
  • Neu erstellen...