Tl;dr:
Use Get-WinEvent https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.diagnostics/get-winevent相反并添加-Oldest
范围:
Get-WinEvent -LogName Microsoft-Windows-DNSServer/Analytical -Oldest
Get-EventLog https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-eventlog是用于读取 Windows 事件日志的旧版 cmdlet,它不能用于读取所有可用的事件日志(请查找此 cmdlet 文档中的注释):
Get-EventLog
使用已弃用的 Win32 API。结果可能不准确。使用Get-WinEvent
cmdlet 代替。
With Get-WinEvent https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.diagnostics/get-winevent您可以使用列出所有可用日志Get-WinEvent -ListLog *
或者您可以过滤所有 DNS 相关日志:
Get-WinEvent -ListLog *DNS* | Select-Object -Property LogName
Output:
LogName
-------
DNS Server
Microsoft-Windows-DNS-Client/Operational
Microsoft-Windows-DNSServer/Audit
Add the -Force
参数也可查看Debug and 分析型 events:
LogName
-------
DNS Server
Microsoft-Windows-DNS-Client/Operational
Microsoft-Windows-DNSServer/Analytical
Microsoft-Windows-DNSServer/Audit
您可以通过将这些名称传递给-LogName
范围:
Get-WinEvent -LogName Microsoft-Windows-DNSServer/Audit
尝试读取时会出现错误Microsoft-Windows-DNSServer/Analytical
log:
Get-WinEvent : The Microsoft-Windows-DNSServer/Analytical event log can be read only in the forward chronological order because it is an analytical or a debug log. To see events from the Microsoft-Windows-DNSServer/Analytical event log, use the Oldest parameter in the command.
所以只需添加-Oldest
现在就可以开始了:
Get-WinEvent -LogName Microsoft-Windows-DNSServer/Analytical -Oldest