Skip to content

Instantly share code, notes, and snippets.

@fsackur
Created July 12, 2017 09:14
Show Gist options
  • Save fsackur/409d7b36895c2887c68068d2785c2c9f to your computer and use it in GitHub Desktop.
Save fsackur/409d7b36895c2887c68068d2785c2c9f to your computer and use it in GitHub Desktop.
function Get-DnsCache {
<#
.Synopsis
Get entries from the DNS cache
#>
$Matches.Clear()
$DnsCache = (ipconfig /displaydns) -join "`r`n"
$Chunks = $DnsCache -split '\n\s*\r'
$Pattern = (New-Object System.Text.StringBuilder).
Append('Record Name[ \.]*: (?<RecordName>\S*)').
Append('\s*').
Append('Record Type[ \.]*: (?<RecordType>\S*)').
Append('\s*').
Append('Time To Live[ \.]*: (?<Ttl>\S*)').
Append('\s*').
Append('Data Length[ \.]*: (?<Length>\S*)').
Append('\s*').
Append('Section[ \.]*: (?<Section>\S*)').
Append('\s*').
Append('.+?Record[ \.]*: (?<Response>\S*)').
ToString()
$DnsEntries = $Chunks | foreach {
if ($_ -match $Pattern) {
$Matches.Remove(0)
New-Object psobject -Property $Matches
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment