אחת הדברים הראשונים שעליך לעשות כאשר אתה מנסה לפתור בעיה דומה הוא לאפשר רישום דיבאג DNS. אבל כאשר אתה נאלץ לבדוק את רישום הדיבאג שנוצר, אתה מתמודד עם התעוררות קשה. הפך זאת לקלה על ידי יצירת סקריפט מנתח לוג דיבאג DNS עם PowerShell!
כיצד לבנות מנתח לוג דיבאג DNS עם PowerShell
יש לך מספר אפשרויות שונות לניתוח, אך במקרה שלי, אני זקוק למידע נוסף על עדכונים דינמיים. כך נראית התצורה שלי על אחד משרתי ה-DNS שלי.

כאשר זה מופעל, יתחיל ליצור קובץ לוג בנתיב הקובץ שאתה מציין שנראה כמו זה:

השורה הראשונה של השורות שסומנו היא כתובת ה-IP והשורה האחרונה היא הרשומה של DNS שניסה לעדכן. אלו סומנו מסיבות ברורות. בהתאם לאפשרויות שתבחר, קובץ הלוג הזה יכול להפוך לעצום ולא נמצא בפורמט הקל ביותר לקריאה.
מה אם אני רוצה לסנן רק כתובת IP יחידה או להקטין את זה לפי זמן מסוים? אתה לא יכול לעשות זאת עם קובץ הלוג המותקן. זה הסיבה שיצרתי סקריפט מנתח לוג דיבאג DNS עם PowerShell.
הסקריפט הבא מפרק את קובץ הלוג הזה וממיר אותו לקובץ CSV נחמד שנראה כך:

שזה נראה הרבה יותר טוב, נכון? הסקריפט בודק את קובץ הלוגים לאורעים שגיאה ומפרט את התאריך, כתובת ה-IP והשגיאה, ומכניס את כל זה ל-CSV בפורמט נוח. הוא גם מתעלם מכל כתובות ה-IP של שרתי DNS.
לסיבה מסוימת, למרות האופציה שבה תבחר, אני מצאתי שכתובות ה-IP של שרתי DNS עצמם חוזרות פעמים רבות. אני רק צריך לדעת את כתובת ה-IP של הלקוח שיש לו בעיה בעדכון הרשומה של DNS שלו.
This file contains 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
#requires -Module ActiveDirectory | |
$dnsServer = '' ## This is the server name as a NETBIOS or FQDN | |
$OutputFilePath = 'C:\DNSDebugLogSummary.csv' ## The CSV file that will be created | |
## The log file you specified in the debug logging dialog box | |
$DnsDebugLogFilePath = "\$dnsServer\c$\DnsDebugLog.log" | |
## Find all of the DNS server IPs in the current domain | |
$DnsServerIPs = ((Get-ADDomain).ReplicaDirectoryServers | Resolve-DnsName).IPAddress | |
Write-Verbose –Message "Found DNS servers $($DnsServerIPs -join ',')" | |
## Find all lines in the log file that don't contain the strings 'NOERROR' or are blank. This | |
## retrieves only the lines with errors in them. | |
Select-String –Pattern 'NOERROR|^\s*' –Path $DnsDebugLogFilePath -NotMatch | foreach { | |
try { | |
## Find lines containing an IP address | |
if ($_.Line -match '\b(?:\d{1,3}\.){3}\d{1,3}\b') { | |
Write-Verbose –Message 'Found line with IP address.' | |
$IP = $Matches[0] | |
## If the IP isn't a DNS server it must be a client IP | |
if ($DnsServerIPs -notcontains $IP) { | |
Write-Verbose "Processing IP '$IP'" | |
$Split = $_.Line.Split(' ') | |
$Date = $Split[0] | |
$Time = $Split[1] + $Split[2] | |
$Err = [regex]::Match($_.Line, '\[(.*)\]').Groups[1].Value | |
[pscustomobject]@{ 'Date' = "$Date $Time"; 'IP' = $IP; 'Error' = $Err } | |
} | |
} | |
} catch { | |
Write-Warning $_.Exception.Message | |
} | |
} | Export-Csv –Path $OutputFilePath –Append –NoTypeInformation |