Skip to content

Instantly share code, notes, and snippets.

@AfroThundr3007730
Last active September 19, 2022 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AfroThundr3007730/2123fd25d06deaa328c43e70e1f78021 to your computer and use it in GitHub Desktop.
Save AfroThundr3007730/2123fd25d06deaa328c43e70e1f78021 to your computer and use it in GitHub Desktop.
Resolves a DNS record on all active DCs in a domain
function Resolve-DnsRecordAllDCs {
<# .SYNOPSIS
Resolves a DNS record on all active DCs in a domain #>
[Alias('nslookup_all')]
Param(
# Name to resolve
[Parameter(Mandatory, ValueFromPipeline)]
[string]$Name,
# Type of record
[Parameter(ValueFromPipelineByPropertyName)]
[string]$Type = 'A',
# Batch size for parallel query
[Parameter()]
[int]$ThrottleLimit = 10
)
Resolve-DnsName -Type 'SRV' -Name _ldap._tcp.dc._msdcs.$env:USERDNSDOMAIN |
Where-Object { $_.Type -eq 'SRV' } | ForEach-Object -ThrottleLimit $ThrottleLimit -Parallel {
if (Test-Connection -TargetName $_.NameTarget -Count 1 -TimeoutSeconds 1 -Quiet) {
Resolve-DnsName -Type $Using:Type -Name $Using:Name -Server $_.NameTarget `
-DnsOnly -QuickTimeout -ErrorAction SilentlyContinue
}
} | Where-Object { $_.QueryType -eq $Type } # | Select-Object -Unique
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment