Jump to content
IanN1990

AD - Check if domain is offline / unavailable or connection time out [Solved]

Recommended Posts

IanN1990

Hi,

I have a issue at the moment that some of my domain controller go down and that causes big delays in my script.

Is there any way of checking a domains status / availability before attempting to connect or if not is there any way to set a time-out when opening a connection (similar to _ieLoadwait timout)?

Ian

Edited by IanN1990

Share this post


Link to post
Share on other sites
water

_AD_ListDomainControllers returns a list of all DCs. Do a ping and you will - at least - know if the server itself is up.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
IanN1990

As your the creator of the most useful AD UDF

I will close this as solved :) 

Share this post


Link to post
Share on other sites
water

Thanks :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
IanN1990

As your the creator, whats your honest view on this code.

#include "ad.au3"

   ConsoleWrite(@Crlf & CheckFastestADConnection())

   Func CheckFastestADConnection()
      Dim $FastestADConnection = 10000, $FastestConnection=""

      _AD_Open()
      $ADDomainArray = _AD_ListDomainControllers()
      _AD_close()

         For $i=1 to ubound($ADDomainArray)-1
            $Ping = Ping($ADDomainArray[$i][2], 10)
            If $Ping < 10 Then
               $ADConnectionTest = TimerInit()
               _AD_Open("", "", "", $ADDomainArray[$i][2], "")
               _AD_Close()

               $TimerDiff = Timerdiff($ADConnectionTest)
               ConsoleWrite($ADDomainArray[$i][2] & " " & $TimerDiff & @CRLF)
                If $FastestADConnection > $TimerDiff then
                  $FastestADConnection = $TimerDiff
                  $FastestConnection = $ADDomainArray[$i][2]
               EndIf
            EndIf
         Next
      Return $FastestConnection
   EndFunc

1. Connects to AD using local details

2. Gets a List of all the Domain Controllers

3. Pings each controller if its less < 10 then controller is online

4. Open / Close connection, recording time to complete this

5. Compares against last controller timer, lowest gets stored.

 

Is this a good way to find out which controller is the fastest?

Ian

Edited by IanN1990

Share this post


Link to post
Share on other sites
water

How many DCs are we talking about?
IIRC when connecting to a domain Windows selects the best/fastest DC if you do not specify one. So I think just calling _AD_Open() should give you the best result.

Maybe this PS helps: https://blogs.msdn.microsoft.com/javaller/2013/07/29/powershell-one-liner-for-finding-lowest-latency-domain-controller/


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Jos

A ping to just the domainname should get you are reply from the "nearest" DC if I remember correctly.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
IanN1990

I have 8 domain controllers, using the ping command i get a response of either 1 or 5

Share this post


Link to post
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

×