This article is contributed. See the original author and article here.

Hi Team, Eric Jansen here again, this time to add on to Joel Vickery’s previous post discussing how to view the DNS Analytic Logs without having to disable them.  It’s a great read if you haven’t already seen it…. however, there’s been a very unfortunate death in the family since that posting…


 


EJansen_0-1605659274348.png


 


It was a sad day when the news posted that Microsoft Message Analyzer was no more; because it was an extremely feature rich tool that myself and a lot of others still use today, albeit of the last release – that can no longer be downloaded.  In situations like this one though, we must adapt and overcome, to find new ways to accomplish the same goals.  This is where I thought I might be able to help empower you guys to be able to do more, using the power of PowerShell.  Reading through online forums I’ve seen numerous posts where folks say that it’s not possible to view the DNS Analytical log while it’s running.  I’m here to tell you guys that you absolutely can, and not just using the methods that Joel outlined in his blog. 


 


As you may have noticed in part one of the series, I used several cmdlets that if you tried to follow along with the posting, wouldn’t have worked for you.  That’s because they’re all custom functions that I’ve personally written, since I spend a fair amount of time digging around in these logs, just to make my life a bit easier.  I’ve written a series of functions (Seven to be exact) to help with DNS Analytic Log configuration.  As we move along through the series, I’ll likely share more of them, and at some point, I’ll see if I can muster up the motivation to setup a code repository on GitHub, if the interest is there.


 


For today’s topic though, I thought I’d share one of my shiny new functions, I call her…… Show-DNSAnalyticLog.  I decided that I’d even reveal the magic behind the curtains (OK, it’s not that magical, but it does what I want it to.).  In reality, there’s only one real line that does the work in the wrapper-of-a-function that I wrote, and that’s the line that uses Get-WinEvent, specifically with the use of the -Oldest parameter; that’s the key.


 


So, let’s take a look at this sample code and a few notes that I’ve added in there:


 

<#
.Synopsis
   Shows what's currently in the DNS Analytic log regardless of if the log is enabled or disabled.

.DESCRIPTION
   See Synopsis.

.EXAMPLE
   Show-DNSAnalyticLog

.NOTES
 Alpha Version - 13 Oct 2020

 Disclaimer:

 This is a sample script.  Sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.

 AUTHOR: Eric Jansen, MSFT
#>

function Show-DNSAnalyticLog
{
    [CmdletBinding()]
    [Alias('SDAL')]

    Param
    (
        #Parameter to define the server.
        [Parameter(Mandatory=$false,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        $Server = $env:COMPUTERNAME
    )

        #Define the DNS Analytical Log name.   
        $EventLogName = 'Microsoft-Windows-DNSServer/Analytical'
        
        Try{

            #Step 1 for Show-DNSAnalyticLog.....does the Analytical log even exist on the computer to be enumerated?
            If(Get-WinEvent -listlog $EventLogName  -ErrorAction SilentlyContinue){
    
                $DNSAnalyticalLogData = Get-WinEvent -listlog $EventLogName
                If(($DNSAnalyticalLogData.LogFilePath).split("")[0] -eq '%SystemRoot%'){$DNSAnalyticalLogPath = $DNSAnalyticalLogData.LogFilePath.Replace('%SystemRoot%',"$env:Windir")}
 
            }
            Else{
            Write-Host "The Microsoft-Windows-DNSServer/Analytical log couldn't be found to be enumerated.`n" -ForegroundColor Red
            Write-Host "Ensure that this function is being run on a DNS Server that has the Microsoft-Windows-DNSServer/Analytical log."
            Return
            }
        
            #Check to make sure that the log can be found to be read, because if it's cleared, via the GUI, or wevtutil, or Clear-DNSAnalyticLog, the .etl is not just cleared, but deleted.
            If(Test-Path $DNSAnalyticalLogPath){
            Get-WinEvent -Path $DNSAnalyticalLogPath -Oldest
            }
            Else{
            Write-Warning "The $($EventLogName) log doesn't exist at the expected path:"
            Write-Host "`n$($DNSAnalyticalLogPath)"
            Return
            }      
                        
        }
        Catch{
        $_.Exception.Message      
        }
}

 


So, once you load that guy up, all you need to do is type Show-DNSAnalyticLog, and you’re off to the races.  It’ll dump an unparsed / unfiltered list of events that’ll scroll down the screen until everything’s dumped out for your viewing pleasure.  One thing to take into consideration though, is that when dumping ALL events (and there could be millions of them), then it could take a while before the scroll fest begins.  Once it does though, it’ll look something like this…again, starting from the oldest created event, racing to catch up with the newest written event:


 


Note:  The below just shows that the log is in fact enabled and was written to, even after I showed the current time, followed by the running of the function to show the events that are in the log.


 

EJansen_1-1605659274500.png


 


Anyhow, nothing crazy, but if it can help someone else, then my job is done (for the time being). 


 


But who wants unparsed / unfiltered logs when you’re on a hunt?  Gross.  Maybe we can talk about that in a future post. ;)


 


Until next time…


 

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.