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 DHCP
Windows DHCP
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.DHCP: Dynamic Host Configuration Protocol (DHCP). A communications protocol that lets network administrators manage centrally and automate the assignment of Internet Protocol (IP) addresses in an organization's network.
1,021 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,362 questions
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 44,776 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. Sunny Qi 10,896 Reputation points Microsoft Vendor
    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