Jump to content

Recommended Posts

Posted

You could try to connect to Global Catalogue as described here.
When you run

$aDCs = _AD_ListDomainControllers(False, True)
_ArrayDisplay($aDCs)

you get list of DCs including the GC (Global Catalogue). Then use this information in _AD_Open to connect to the GC as described by the link above.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 6/17/2020 at 5:10 PM, water said:

You could try to connect to Global Catalogue as described here.
When you run

$aDCs = _AD_ListDomainControllers(False, True)
_ArrayDisplay($aDCs)

you get list of DCs including the GC (Global Catalogue). Then use this information in _AD_Open to connect to the GC as described by the link above.

Expand  

Nice I'll try! Right now I'm in home office and need to use a vpn! If it fails I'll try into one of the branches or something! Again thanks for you time and help! :D

 

Posted
  On 6/17/2020 at 5:27 PM, edumanilha said:

Nice I'll try! Right now I'm in home office and need to use a vpn! If it fails I'll try into one of the branches or something! Again thanks for you time and help! :D

 

Expand  

I got this error
 

image.png.925c1061e6bd6b2cdee650955d3373ba.png

when I try to run this:

#include<AD.au3>

Local $iResult = _AD_Open()
Local $aDCs = _AD_ListDomainControllers(False, True)
For $iIndex = 1 to $aDCs[0][0]
   If $aDCs[$iIndex][6] = True Then ConsoleWrite("DC " & $aDCs[$iIndex][0] & " is a Global Catalog")
Next

_ArrayDisplay($aDCs)
_AD_Close()

 

Posted

Can you please insert

_AD_ErrorNotify(2)

after _AD_Open and run the script again?
You will get a MsgBox explaining what causes the error.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)
  On 6/17/2020 at 8:16 PM, water said:

Can you please insert

_AD_ErrorNotify(2)

after _AD_Open and run the script again?
You will get a MsgBox explaining what causes the error.

Expand  

Windescription = Non operational server...

Edited by edumanilha
Posted

Could you please add the following function to your script and call _AD_ListDomainControllersEX instead of _AD_ListDomainControllers? The error should be gone.

; #FUNCTION# ====================================================================================================================
; Name...........: _AD_ListDomainControllers
; Description ...: Enumerates all Domain Controllers (returns information about: Domain Controller, site, subnet and Global Catalog).
; Syntax.........: _AD_ListDomainControllers([$bListRO = False[, $bListGC = False]])
; Parameters ....: $bListRO - [optional] If set to True only returns RODC (read only domain controllers) (default = False)
;                  $bListGC - [optional] If set to True queries the DC for a Global Catalog. Disabled for performance reasons (default = False)
; Return values .: Success - One-based two dimensional array with the following information:
;                  |0 - Domain Controller: Name
;                  |1 - Domain Controller: Distinguished Name (FQDN)
;                  |2 - Domain Controller: DNS host name
;                  |3 - Site: Name
;                  |4 - Site: Distinguished Name (FQDN)
;                  |5 - Site: List of subnets that can connect to the site using this DC in the format x.x.x.x/mask - multiple subnets are separated by comma
;                  |6 - Global Catalog: If $bListGC = True you get one of the following values:
;                       True if the DC is a Global Catalog, False if it is no GC, "" if RootDSE of the DC could not be accessed
;                  Failure - "", sets @error to:
;                  |1 - No Domain Controllers found. @extended is set to the error returned by LDAP
; Author ........: water (based on VB functions by Richard L. Mueller)
; Modified.......:
; Remarks .......: This function only lists writeable DCs (default). To list RODC (read only DCs) use parameter $bListRO
; Related .......:
; Link ..........: http://www.rlmueller.net/Enumerate%20DCs.htm
; Example .......: Yes
; ===============================================================================================================================
Func _AD_ListDomainControllersEX($bListRO = False, $bListGC = False)

    If $bListRO = Default Then $bListRO = False
    If $bListGC = Default Then $bListGC = False
    Local $oDC, $oSite, $oResult
    Local Const $NTDSDSA_OPT_IS_GC = 1
    $__oAD_Command.CommandText = "<LDAP://" & $sAD_HostServer & "/" & $sAD_Configuration & ">;(objectClass=nTDSDSA);ADsPath;subtree"
    If $bListRO Then $__oAD_Command.CommandText = "<LDAP://" & $sAD_HostServer & "/" & $sAD_Configuration & ">;(objectClass=nTDSDSARO);ADsPath;subtree"
    Local $oRecordSet = $__oAD_Command.Execute
    If @error Or Not IsObj($oRecordSet) Or $oRecordSet.RecordCount = 0 Then Return SetError(1, @error, "")
    ; The parent object of each object with objectClass=nTDSDSA is a Domain
    ; Controller. The parent of each Domain Controller is a "Servers"
    ; container, and the parent of this container is the "Site" container.
    $oRecordSet.MoveFirst
    Local $aResult[1][7], $iCount1 = 1, $aSubNet, $aTemp, $sTemp
    Do
        ReDim $aResult[$iCount1 + 1][7]
        $oResult = __AD_ObjGet($oRecordSet.Fields("AdsPath").Value)
        $oDC = __AD_ObjGet($oResult.Parent)
        $aResult[$iCount1][0] = $oDC.Get("Name")
        $aResult[$iCount1][1] = $oDC.serverReference
        $aResult[$iCount1][2] = $oDC.DNSHostName
        $oResult = __AD_ObjGet($oDC.Parent)
        $oSite = __AD_ObjGet($oResult.Parent)
        $aResult[$iCount1][3] = StringMid($oSite.Name, 4)
        $aResult[$iCount1][4] = $oSite.distinguishedName
        $aSubNet = $oSite.GetEx("siteObjectBL")
        For $iCount2 = 0 To UBound($aSubNet) - 1
            $aTemp = StringSplit($aSubNet[$iCount2], ",")
            $sTemp = StringMid($aTemp[1], 4)
            If $iCount2 = 0 Then
                $aResult[$iCount1][5] = $sTemp
            Else
                $aResult[$iCount1][5] = $aResult[$iCount1][5] & "," & $sTemp
            EndIf
        Next
        If $bListGC Then
            ; Is the DC a GC? Taken from: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/computermanagement/ad/
            Local $oDCRootDSE = __AD_ObjGet("LDAP://" & $oDC.DNSHostName & "/rootDSE")
            If @error = 0 Then
                Local $sDsServiceDN = $oDCRootDSE.Get("dsServiceName")
                Local $oDsRoot = __AD_ObjGet("LDAP://" & $oDC.DNSHostName & "/" & $sDsServiceDN)
                Local $iDCOptions = $oDsRoot.Get("options")
                If BitAND($iDCOptions, $NTDSDSA_OPT_IS_GC) = 1 Then
                    $aResult[$iCount1][6] = True
                Else
                    $aResult[$iCount1][6] = False
                EndIf
            EndIf
        EndIf
        $oRecordSet.MoveNext
        $iCount1 += 1
    Until $oRecordSet.EOF
    $oRecordSet.Close
    $aResult[0][0] = UBound($aResult, 1) - 1
    $aResult[0][1] = UBound($aResult, 2)
    Return $aResult

EndFunc   ;==>_AD_ListDomainControllers

 

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 6/17/2020 at 8:59 PM, water said:

Could you please add the following function to your script and call _AD_ListDomainControllersEX instead of _AD_ListDomainControllers? The error should be gone.

; #FUNCTION# ====================================================================================================================
; Name...........: _AD_ListDomainControllers
; Description ...: Enumerates all Domain Controllers (returns information about: Domain Controller, site, subnet and Global Catalog).
; Syntax.........: _AD_ListDomainControllers([$bListRO = False[, $bListGC = False]])
; Parameters ....: $bListRO - [optional] If set to True only returns RODC (read only domain controllers) (default = False)
;                  $bListGC - [optional] If set to True queries the DC for a Global Catalog. Disabled for performance reasons (default = False)
; Return values .: Success - One-based two dimensional array with the following information:
;                  |0 - Domain Controller: Name
;                  |1 - Domain Controller: Distinguished Name (FQDN)
;                  |2 - Domain Controller: DNS host name
;                  |3 - Site: Name
;                  |4 - Site: Distinguished Name (FQDN)
;                  |5 - Site: List of subnets that can connect to the site using this DC in the format x.x.x.x/mask - multiple subnets are separated by comma
;                  |6 - Global Catalog: If $bListGC = True you get one of the following values:
;                       True if the DC is a Global Catalog, False if it is no GC, "" if RootDSE of the DC could not be accessed
;                  Failure - "", sets @error to:
;                  |1 - No Domain Controllers found. @extended is set to the error returned by LDAP
; Author ........: water (based on VB functions by Richard L. Mueller)
; Modified.......:
; Remarks .......: This function only lists writeable DCs (default). To list RODC (read only DCs) use parameter $bListRO
; Related .......:
; Link ..........: http://www.rlmueller.net/Enumerate%20DCs.htm
; Example .......: Yes
; ===============================================================================================================================
Func _AD_ListDomainControllersEX($bListRO = False, $bListGC = False)

    If $bListRO = Default Then $bListRO = False
    If $bListGC = Default Then $bListGC = False
    Local $oDC, $oSite, $oResult
    Local Const $NTDSDSA_OPT_IS_GC = 1
    $__oAD_Command.CommandText = "<LDAP://" & $sAD_HostServer & "/" & $sAD_Configuration & ">;(objectClass=nTDSDSA);ADsPath;subtree"
    If $bListRO Then $__oAD_Command.CommandText = "<LDAP://" & $sAD_HostServer & "/" & $sAD_Configuration & ">;(objectClass=nTDSDSARO);ADsPath;subtree"
    Local $oRecordSet = $__oAD_Command.Execute
    If @error Or Not IsObj($oRecordSet) Or $oRecordSet.RecordCount = 0 Then Return SetError(1, @error, "")
    ; The parent object of each object with objectClass=nTDSDSA is a Domain
    ; Controller. The parent of each Domain Controller is a "Servers"
    ; container, and the parent of this container is the "Site" container.
    $oRecordSet.MoveFirst
    Local $aResult[1][7], $iCount1 = 1, $aSubNet, $aTemp, $sTemp
    Do
        ReDim $aResult[$iCount1 + 1][7]
        $oResult = __AD_ObjGet($oRecordSet.Fields("AdsPath").Value)
        $oDC = __AD_ObjGet($oResult.Parent)
        $aResult[$iCount1][0] = $oDC.Get("Name")
        $aResult[$iCount1][1] = $oDC.serverReference
        $aResult[$iCount1][2] = $oDC.DNSHostName
        $oResult = __AD_ObjGet($oDC.Parent)
        $oSite = __AD_ObjGet($oResult.Parent)
        $aResult[$iCount1][3] = StringMid($oSite.Name, 4)
        $aResult[$iCount1][4] = $oSite.distinguishedName
        $aSubNet = $oSite.GetEx("siteObjectBL")
        For $iCount2 = 0 To UBound($aSubNet) - 1
            $aTemp = StringSplit($aSubNet[$iCount2], ",")
            $sTemp = StringMid($aTemp[1], 4)
            If $iCount2 = 0 Then
                $aResult[$iCount1][5] = $sTemp
            Else
                $aResult[$iCount1][5] = $aResult[$iCount1][5] & "," & $sTemp
            EndIf
        Next
        If $bListGC Then
            ; Is the DC a GC? Taken from: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/computermanagement/ad/
            Local $oDCRootDSE = __AD_ObjGet("LDAP://" & $oDC.DNSHostName & "/rootDSE")
            If @error = 0 Then
                Local $sDsServiceDN = $oDCRootDSE.Get("dsServiceName")
                Local $oDsRoot = __AD_ObjGet("LDAP://" & $oDC.DNSHostName & "/" & $sDsServiceDN)
                Local $iDCOptions = $oDsRoot.Get("options")
                If BitAND($iDCOptions, $NTDSDSA_OPT_IS_GC) = 1 Then
                    $aResult[$iCount1][6] = True
                Else
                    $aResult[$iCount1][6] = False
                EndIf
            EndIf
        EndIf
        $oRecordSet.MoveNext
        $iCount1 += 1
    Until $oRecordSet.EOF
    $oRecordSet.Close
    $aResult[0][0] = UBound($aResult, 1) - 1
    $aResult[0][1] = UBound($aResult, 2)
    Return $aResult

EndFunc   ;==>_AD_ListDomainControllers

 

Expand  

It worked! I can see the servers now...Thanks!

Posted

Fixed in the 1.5.0.1 version of the UDF which I uploaded today.

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 4 weeks later...
Posted

If you check the checkbox "User must change password at next logon" property pwdlastset is set to 0.
Function _AD_GetPasswordInfo returns an array with "1601/01/01 00:00:00" in element 8 when the password has never been set = User must change password at next logon
Function _AD_IsPasswordExpired returns 1 if the password of the user or computer account has expired (means password has expired or has never been set).

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 7/13/2020 at 10:21 AM, water said:

If you check the checkbox "User must change password at next logon" property pwdlastset is set to 0.
Function _AD_GetPasswordInfo returns an array with "1601/01/01 00:00:00" in element 8 when the password has never been set = User must change password at next logon
Function _AD_IsPasswordExpired returns 1 if the password of the user or computer account has expired (means password has expired or has never been set).

Expand  

thanks :) that's just what i needed

Posted

Glad to be of service :)
N.B.: Please test your scripts to
make sure that they work as expected and that everything I posted above is true - didn't have a look at this part of the UDF for months ;)

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 7/13/2020 at 10:29 AM, water said:

Glad to be of service :)
N.B.: Please test your scripts to
make sure that they work as expected and that everything I posted above is true - didn't have a look at this part of the UDF for months ;)

Expand  
Global $result = _AD_IsPasswordExpired()
MsgBox("","",$result)

_AD_IsPasswordExpired seems to return 0 whenever the checkbox is enabled or not

Posted (edited)

How long did you wait between checking the box and running your script? Maybe it is an AD sync problem?

Edit: What's the value of @error when $result = 0?

Edited by water

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 7/13/2020 at 1:08 PM, water said:

How long did you wait between checking the box and running your script? Maybe it is an AD sync problem?

Edit: What's the value of @error when $result = 0?

Expand  

the value of @error is also 0, it doesen't seem likely it's a sync issue.
the password for the user is still reset, and hasn't been changed, and the checkbox is enabled, but it still returns 0

Posted

You could run _AD_GetObjectProperties for the user with the checkbox enabled, save the result, disable the checkbox and do the previous steps again.
By comparing the saved results we could see which property holds the "needs to change password on next logon".

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

That solved the problem :)

 

the Attribute: pwnLastSet gets updated to 1601/01/01 00:00:00 when you check : User must change password at next logon.
However, I can't seem to grab the information, it returns nothing from the attribute:

$pwdLastSet = _AD_GetObjectAttribute($input, "pwdLastSet")

$pwdLastSet = _AD_GetObjectAttribute($input, "pwdLastSet")

 

Edited by legend
Posted

What's the value of property pwdlastset?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)
  On 7/15/2020 at 9:51 AM, water said:

What's the value of property pwdlastset?

Expand  

the value of pwdLastSet is 1601/01/01 00:00:00

2020-07-15_115923.png

 

If i type a wrong username, it fails, but if i try with a correct username, it just returns nothing, but doesen't fail.

 

EDIT: i got it to work :)

$aListProp = _AD_GetObjectProperties(@UserName, "pwdLastSet")
msgbox(0,"", $aListProp[1][1])

 

Edited by legend
Posted

"Unfortunately" _AD_GetObjectProperties translates values into a readable format.
Could you please run the following modified version of _AD_GetObjectproperties? It displays the pwdlastset bigint as high and low before translating it to a readable format.
Both values should be 0.

  Reveal hidden contents

 

My UDFs and Tutorials:

  Reveal hidden contents

 

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
×
×
  • Create New...