Skip to content

Instantly share code, notes, and snippets.

@dstreefkerk
Forked from randomvariable/dns_client_log.ps1
Created March 21, 2019 04:54
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 dstreefkerk/ffce7c6d015c6d9c8d0b4e65f763dcea to your computer and use it in GitHub Desktop.
Save dstreefkerk/ffce7c6d015c6d9c8d0b4e65f763dcea to your computer and use it in GitHub Desktop.
DNS Client Logging on Windows
function Start-DNSClientLog {
$DnsOpLog = Get-WinEvent -ListLog Microsoft-Windows-DNS-Client/Operational
$DnsOpLog.IsEnabled = $true
$DnsOpLog.SaveChanges()
}
function Get-DNSClientQueries {
foreach($event in (get-winevent Microsoft-Windows-DNS-Client/Operational | % { [xml]$_.ToXml() })) {
$Query = ($event.Event.EventData.Data | Where-Object { $_.Name -eq "QueryName" }).'#text'
if($null -eq $Query) { return }
New-Object PSObject -Property @{
"Date" = [DateTime]$event.Event.System.TimeCreated.SystemTime;
"Query" = $Query
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment