Jump to content

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


IanN1990
 Share

Recommended Posts

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
Link to comment
Share on other sites

_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 2022-02-19 - Version 1.6.1.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 (NEW 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

Thanks :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

  • Developers

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 etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...