PowerShell 查询登陆失败的日志


无论何时用户使用了非法的用户凭据登陆机器失败后,都会在系统日志的security下生成一条日志。 下面的函数可以从系统日志中读取这些日志,并列出它们。(需要管理员权限)

# 需要管理员权限!
function Get-LogonFailure
{
      param($ComputerName)
      try
      {
          Get-EventLog -LogName security -EntryType FailureAudit -InstanceId 4625 -ErrorAction Stop @PSBoundParameters | 
                  ForEach-Object {
                    $domain, $user = $_.ReplacementStrings[5,6]
                    $time = $_.TimeGenerated
                    "Logon Failure: $domain\$user at $wann"
                }
      }
      catch
      {
            if ($_.CategoryInfo.Category -eq 'ObjectNotFound')
            {
                  Write-Host "No logon failures found." -ForegroundColor Green
            }
            else
            {
                  Write-Warning "Error occured: $_"
            }
      }
}

注意:该函数也支持远程处理。你可以使用-ComputerName来指定一个远程机器。远程系统需要运行RemoteRegistry服务,并且你需要你本地的管理员拥有远程系统上的权限。

原文链接Finding Logon Failures

本文链接: https://www.pstips.net/finding-logon-failures.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

关于 Mooser Lee

我是一个Powershell的爱好者,创建了PowerShell中文博客,热衷于Powershell技术的搜集和分享。本站部分内容来源于互联网,不足之处敬请谅解,并欢迎您批评指正。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注