top of page

PowerShell - LDap Ping Times across DC's

  • Writer: Jon Boyette
    Jon Boyette
  • Jan 10, 2022
  • 1 min read

Save as LDapPing.ps1 and run, outputs to c:\temp\LDap_Time_MeasureMents_Forest.csv, measures time across DC's for 1 minute to compare latency

####User Variables###


$IntervalSeconds=1


$RunMinutes=1


$LogFile=".\LDAPTimes.csv"


###########################


Add-Type -AssemblyName System.DirectoryServices.Protocols


$LogFile=".\LDAPTimes.csv"


$DomainControllers = Get-ADDomainController -Filter * | Select Name, IPv4Address, Domain, Site


$StartDate=Get-Date


$Results = @()


do


{


foreach ($DomainController in $DomainControllers)


{


[String] $LdapServer=$DomainController.IPv4Address


[Int32] $Port=389


[Boolean] $FullyQualifiedDnsHostName=$False


[Boolean] $Connectionless=$True


$SearchFilter="(&(DnsDomain=$($DomainController.Domain))(NtVer=\06\00\00\02))"


$SearchRequest=new-object System.DirectoryServices.Protocols.SearchRequest


$SearchRequest.Scope="Base"


$SearchRequest.Filter=$SearchFilter


$LdapIdentifier=new-object System.DirectoryServices.Protocols.LdapDirectoryIdentifier($LdapServer, $Port, $FullyQualifiedDnsHostName, $Connectionless)


$LdapConnection=new-object System.DirectoryServices.Protocols.LdapConnection($LdapIdentifier)


$Result = New-Object System.Object


$Milliseconds=(Measure-Command {$LdapConnection.SendRequest($SearchRequest)}).TotalMilliseconds


$Result | Add-Member -Type NoteProperty -Name DateTime -Value (Get-Date)


$Result | Add-Member -Type Noteproperty -Name Site -Value $DomainController.Site


$Result | Add-Member -Type Noteproperty -Name Server -Value $DomainController.Name


$Result | Add-Member -Type Noteproperty -Name Milliseconds -Value $Milliseconds


$Result | Export-Csv -Path $Logfile -Append -NoTypeInformation


$Results += $Result


}


Start-Sleep -Seconds $IntervalSeconds


}


While ($StartDate.AddMinutes($RunMinutes) -gt (Get-Date))


$Results | Export-Csv c:\temp\LDap_Time_MeasureMents_Forest.csv



 
 
 

Recent Posts

See All
PowerShell - List All Domain SPNs

Save as same List_ALL_SPNs.ps1 or similar, this LDap calls the Domain for all Service Principal names and accounts related #Build LDAP...

 
 
 
PowerShell - Start-Monitoring

This is a great script used to Monitor and Email if a server is up or down, once ran, and smtp and from address is set, then run:...

 
 
 

Comments


Post: Blog2 Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Boyette Technical Services. Proudly created with Wix.com

bottom of page