Find all the DC-Locator SRV entries from all ad-sites within a domain

The estimated reading time 2 minutes

Find all the DC-Locator SRV entries from all ad-sites within a domain

It is always necessary to control the DC Locator SRV entries of the sites within a domain with several sites. With one or two sites that is not a big issue. But when it comes to 5-10 sites or more, it  looks quite different. So there are a lot of clicks , which can be saved with a small Powershell script.
For information about the individual DNS entries within an AD, see the following link:
This articel refers as described to the following facts:
Well, the SRV entries should be obsolete, often long logon times of the clients are a result. These clients try to connect to the DC of the site until it is determined that this is no longer accessible for the first.
Here is the script:
#define the log path!
$logpath = "C:\temp\sites-"

####################################################
#find date and convert to string
$date=((Get-Date).ToString('yyyy-MM-dd-HH-mm-ss'))
#defines the path where to find the log file of this script
$Logfile = $logpath+$date+".log"
#convert date and time to string
$date=((Get-Date).ToString('yyyy-MM-dd-HH-mm-ss'))
#get addomain
$domain = ((Get-WmiObject Win32_ComputerSystem).Domain)
#get all sites
$sites = (([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites).Name)
Function Write-Log
{
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}
  Write-Log "Domainname: $domain"
  Write-Log "-------------" 
foreach ($site in $sites){
  $srv = (Resolve-DnsName -Type SRV _ldap._tcp.$site._sites.$domain | ft Name,Type,NameTarget,Port | Out-String )
  Write-Log "Sitename: $site"
  Write-Log "-------------"
  Write-Log "$srv"
}
Nothing has to be done inside the script, only the path for the log file has to be defined. (first line)
The simple variant is to run this script in the ISE, since the variable can be adapted here as well.
The script automatically appends the log file with the current date and time, so nothing is overwritten and the data can also be stored for documentation purposes.
In addition, the respective sites within the logfile are displayed as follows.
OUTPUT

Additional functions will be implemented depending on time and desire. Should someone have special questions / wishes simply leave a message.

Have fun with it.

Print Friendly, PDF & Email
  • Was this Helpful ?
  • yes   no
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments