PowerShell 技能连载 - 直接存取事件日志
通过 Get-EventLog
命令,您可以轻松地转储任意给定的事件日志内容,然而,如果您希望直接存取某个指定的事件日志,您只能使用 -List
参数来完全转储它们,然后选择其中一个您所关注的:
1 | $SystemLog = Get-EventLog -List | Where-Object { $_.Log -eq 'System' } |
一个更简单的方式是使用强制类型转换,类似这样:
1 | $systemLogDirect = [System.Diagnostics.EventLog]'System' |
Simply “convert” the event log name into an object of “EventLog” type. The result looks similar to this and provides information about the number of entries and the log file size:
只需要将时间日志名称“转换”为一个 “EventLog
“ 类型的对象。结果类似这样,并且提供了条目的数量和日志文件尺寸等信息:
1 | PS> $systemLogDirect |
PowerShell 技能连载 - 直接存取事件日志
http://blog.vichamp.com/2018/12/12/accessing-event-logs-directly/