PowerShell 基础知识:查询 Windows Server 事件日志

最标准的服务器管理任务之一是通过事件日志查找有关您要解决的问题的信息。如果您通过 PowerShell 与 Windows Server 交互,则可以使用 Get-EventLog、Clear-EventLog、Limit-EventLog、New-EventLog、Remove-EventLog、Show-EventLog 和 Write-EvengLog cmdlet 与这些事件日志进行交互。 

您最有可能最常使用 Get-Eventlog。要查看可用的事件日志,请运行命令 

Get-EventLog -List

 

Get-EventLog -LogName Security -Newest 10

 

要提取具有特定类型的事件日志条目,请使用 InstanceID 参数。例如,要在安全事件日志 (ID 4624) 中查看最近 10 个成功登录事件,请运行以下命令:

 

Get-EventLog -LogName Security -InstanceID 4624 -Newest 10

  

要在事件日志消息中搜索事件日志以查找特定单词,请使用 Message 参数。例如,要在安全事件日志中搜索单词 Logoff,请使用以下命令: 

Get-EventLog -LogName Security -Message *Logoff*

 

扫描二维码关注公众号,回复: 14440051 查看本文章

Get-EventLog 是一个非常有用的 cmdlet,在使用 Server Core 机器时,或者如果您只是想检查您管理的计算机上是否发生了特定事件,您肯定会使用它。 

猜你喜欢

转载自blog.csdn.net/allway2/article/details/126142326