Jump to content

Recommended Posts

This message tells you that one/more of the Domain Controllers in your domain isn't operational at the moment. Nothing to worry about as long as you get the desired result.

Unfortunately inoperational DCs slow down the script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

But you get a valid date result of your last login?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

This means that at least one DC server was operational and returned the correct value.

How many DCs do you have in your domain?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The following script will display two internal used arrays. First the list of all DCs to be queried and second the last login date for this DC.

#include <AD.au3>

_AD_Open()
If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)

Global $iLLDate = _AD_GetLastLoginDateEX()
MsgBox(64, "Active Directory Functions - Example 1", "Last Login Date for User '" & @UserName & "'" & @CRLF & $iLLDate)

_AD_Close()

Func _AD_GetLastLoginDateEX($sAD_User = @UserName, $sAD_Site = "", $aAD_DCList = "")

    If _AD_ObjectExists($sAD_User) = 0 Then Return SetError(1, 0, 0)
    If Not IsArray($aAD_DCList) And $aAD_DCList <> "" Then Return SetError(3, 0, 0)
    If IsArray($aAD_DCList) And UBound($aAD_DCList, 0) <> 2 Then Return SetError(4, 0, 0)
    If $aAD_DCList = "" Then $aAD_DCList = _AD_ListDomainControllers()
    Local $aAD_Site, $sAD_SingleDC, $bAD_WasIn
    ; Delete all DCs not belonging to the specified site
    $aAD_Site = StringSplit($sAD_Site, ",", 2)
    If UBound($aAD_Site) > 0 And $aAD_Site[0] <> "" Then
        For $iAD_Count1 = $aAD_DCList[0][0] To 1 Step -1
            $bAD_WasIn = False
            For $sAD_SingleDC In $aAD_Site
                If $aAD_DCList[$iAD_Count1][3] = $sAD_SingleDC Then $bAD_WasIn = True
            Next
            If Not $bAD_WasIn Then _ArrayDelete($aAD_DCList, $iAD_Count1)
        Next
        $aAD_DCList[0][0] = UBound($aAD_DCList, 1) - 1
    EndIf
    ; Get LastLogin from all DCs
    Local $aAD_Result[$aAD_DCList[0][0] + 1]
    Local $sAD_LDAPEntry, $oAD_Object, $oAD_RecordSet
    Local $iAD_Error1 = 0, $iAD_Error2 = 0
    For $iCount1 = 1 To $aAD_DCList[0][0]
        If Ping($aAD_DCList[$iCount1][2]) = 0 Then
            $iAD_Error1 += 1
            ContinueLoop
        EndIf
        $__oAD_Command.CommandText = "<LDAP://" & $aAD_DCList[$iCount1][2] & "/" & $sAD_DNSDomain & ">;(sAMAccountName=" & $sAD_User & ");ADsPath;subtree"
        $oAD_RecordSet = $__oAD_Command.Execute ; Retrieve the ADsPath for the object
        ; -2147352567 or 0x80020009 is returned when the service is not operational
        If @error = -2147352567 Or $oAD_RecordSet.RecordCount = 0 Then
            $iAD_Error1 += 1
        Else
            $sAD_LDAPEntry = $oAD_RecordSet.fields(0).value
            $oAD_Object = __AD_ObjGet($sAD_LDAPEntry) ; Retrieve the COM Object for the object
            $aAD_Result[$iCount1] = $oAD_Object.LastLogin
            ; -2147352567 or 0x80020009 is returned when the attribute "LastLogin" isn't defined on this DC
            If @error = -2147352567 Then $iAD_Error2 += 1
            $oAD_Object.PurgePropertyList
        EndIf
    Next
    _ArrayDisplay($aAD_DCList)
    _ArrayDisplay($aAD_Result)
    _ArraySort($aAD_Result, 1, 1)
    ; If error count equals the number of DCs then the user has never logged in
    If $iAD_Error2 = $aAD_DCList[0][0] Then Return SetError(2, 0, 0)
    Return SetError($iAD_Error1, $aAD_DCList[0][0], $aAD_Result[1])

EndFunc   ;==>_AD_GetLastLoginDate

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Some information about the returned value can be found here.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Something like this?

#include <AD.au3>

_AD_Open()
If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)

Global $iLLDate = _AD_GetLastLoginDateEX() ; @Username, "Default-First-Site-Name")
MsgBox(64, "Active Directory Functions - Example 1", "Last Login Date for User '" & @UserName & "'" & @CRLF & $iLLDate)

_AD_Close()

Func _AD_GetLastLoginDateEX($sAD_User = @UserName, $sAD_Site = "", $aAD_DCList = "")

    If _AD_ObjectExists($sAD_User) = 0 Then Return SetError(1, 0, 0)
    If Not IsArray($aAD_DCList) And $aAD_DCList <> "" Then Return SetError(3, 0, 0)
    If IsArray($aAD_DCList) And UBound($aAD_DCList, 0) <> 2 Then Return SetError(4, 0, 0)
    If $aAD_DCList = "" Then $aAD_DCList = _AD_ListDomainControllers()
    Local $aAD_Site, $sAD_SingleDC, $bAD_WasIn
    ; Delete all DCs not belonging to the specified site
    $aAD_Site = StringSplit($sAD_Site, ",", 2)
    If UBound($aAD_Site) > 0 And $aAD_Site[0] <> "" Then
        For $iAD_Count1 = $aAD_DCList[0][0] To 1 Step -1
            $bAD_WasIn = False
            For $sAD_SingleDC In $aAD_Site
                If $aAD_DCList[$iAD_Count1][3] = $sAD_SingleDC Then $bAD_WasIn = True
            Next
            If Not $bAD_WasIn Then _ArrayDelete($aAD_DCList, $iAD_Count1)
        Next
        $aAD_DCList[0][0] = UBound($aAD_DCList, 1) - 1
    EndIf
    ; Get LastLogin from all DCs
    Local $aAD_Result[$aAD_DCList[0][0] + 1]
    Local $sAD_LDAPEntry, $oAD_Object, $oAD_RecordSet
    Local $iAD_Error1 = 0, $iAD_Error2 = 0
    For $iCount1 = 1 To $aAD_DCList[0][0]
        If Ping($aAD_DCList[$iCount1][2]) = 0 Then
            $iAD_Error1 += 1
            ContinueLoop
        EndIf
        $__oAD_Command.CommandText = "<LDAP://" & $aAD_DCList[$iCount1][2] & "/" & $sAD_DNSDomain & ">;(sAMAccountName=" & $sAD_User & ");ADsPath;subtree"
        $oAD_RecordSet = $__oAD_Command.Execute ; Retrieve the ADsPath for the object
        ; -2147352567 or 0x80020009 is returned when the service is not operational
        If @error = -2147352567 Or $oAD_RecordSet.RecordCount = 0 Then
            $iAD_Error1 += 1
        Else
            $sAD_LDAPEntry = $oAD_RecordSet.fields(0).value
            $oAD_Object = __AD_ObjGet($sAD_LDAPEntry) ; Retrieve the COM Object for the object
            $aAD_Result[$iCount1] = $oAD_Object.LastLogin
            $aAD_DCList[$iCount1][6] = $oAD_Object.LastLogin
            ; -2147352567 or 0x80020009 is returned when the attribute "LastLogin" isn't defined on this DC
            If @error = -2147352567 Then $iAD_Error2 += 1
            $oAD_Object.PurgePropertyList
        EndIf
    Next
    _ArrayDisplay($aAD_DCList)
;    _ArrayDisplay($aAD_Result)
    _ArraySort($aAD_Result, 1, 1)
    ; If error count equals the number of DCs then the user has never logged in
    If $iAD_Error2 = $aAD_DCList[0][0] Then Return SetError(2, 0, 0)
    Return SetError($iAD_Error1, $aAD_DCList[0][0], $aAD_Result[1])

EndFunc   ;==>_AD_GetLastLoginDate

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Run example script _AD_GetSystemInfo.au3 and your site will be displayed in the array as element row 8, Col 1. Here it is "Default-First-Site-Name"

So I would change the script to:

Global $iLLDate = _AD_GetLastLoginDateEX(@Username, "Default-First-Site-Name")

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Glad to be of service :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 2 weeks later...

Not with the AD UDF. There has been such discussion on the forum lately. Search for "login script".

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...