Last active
March 31, 2024 18:24
-
-
Save AfroThundr3007730/2123fd25d06deaa328c43e70e1f78021 to your computer and use it in GitHub Desktop.
Resolves a DNS record on all active DCs in a domain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Updated version available in my HelperFunctions module.