to get current hostname or IP of LDAP

Revkov, Stanislav 116 Reputation points
2021-03-19T05:52:43.82+00:00

Hi,

is that possible to get current hostname or IP of LDAP using by an application on the MS Server 2016?
Sometimes one of the LDPA is down and application stops authentication and workaround is only clearing of DNS cache ipconfig /flushdns.
I need to create a Power Shell for that, but I have no idea how to set variable with the name or IP address of the existing using LDAP server.
Can you help please?

Windows for business | Windows Client for IT Pros | Networking | Network connectivity and file sharing
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Revkov, Stanislav 116 Reputation points
    2021-03-22T10:06:20.007+00:00

    Thank you everyone to reply. I confused with LDAP and AD servers. Finaly the application works with AD server, but not LDAP.

    I needed to clear DNS cache on the application server and checked if the new AD in DNS cache is available.
    I created the next PowerShell script and scheduled it in the TaskScheduler every 15 mins. May be it will helpful to someone:

    for($i = 0; $i -le 4; $i++){ipconfig /flushdns
    if(Test-Connection -ComputerName <YourDomain> -Quiet) {break}}

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2021-03-19T14:46:14.81+00:00

    Clear-DnsClientCache is the PowerShell equivalent of "ipconfig /flushdns"

    Is the machine on which you want to clear the cache the LDAP server or is it on a machine that uses the LDAP server? Neither "ipconfig /flushdns" nor Clear-DnsClientCache take any parameters, so it isn't clear why you want to get the IP address (or name) into a variable.

    How do you discover which machine needs to have its DNS cache cleared now? And how do you propose to execute a PowerShell script on the target machine?

    0 comments No comments

  2. Anonymous
    2021-03-22T09:09:18.6+00:00

    Hi,

    Thanks for posting in Q&A platform.

    Please try if nslookup -type=srv _ldap._tcp.DOMAINNAME or nslookup -query=srv _ldap._tcp.DOMAINNAME can help you.

    Best Regards,
    Sunny

    ----------

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.