监视 Windows 操作系统上的本地用户登录
Microsoft Windows 操作系统上的用户登录称为登录事件。在这篇简短的博客文章中,我将向您展示一个 PowerShell One-Liner,它可以检索特定用户的所有用户登录信息。
PowerShell代码
成功的用户登录将通过事件 ID 4648 进行记录。下面的代码重新检索用户 patri 的所有成功登录事件。输出使用 Format-Table cmdlet 进行格式化,以提高可读性。
Get-EventLog -LogName Security -InstanceId 4648 |
Where-Object Message -match "patri" |
Format-Table TimeGenerated,Message -AutoSize -Wrap
更准确地说,为了避免大量输出,我将输出限制为仅显示最后一次成功登录。
Get-EventLog -LogName Security -InstanceId 4648 |
Where-Object Message -match "patri" |
Select-Object -First 1 |
Format-Table TimeGenerated,Message -AutoSize -Wrap
享受使用 PowerShell 监控系统的乐趣!
