您的位置:首页 > 运维架构 > Shell

Powershell获取登陆失败信息

2014-01-21 13:56 288 查看
转自:http://www.pstips.net/finding-logon-failures-2.html

每当用户使用了无效的凭证,将会生成一条安全日志。

下面这个函数实例能读到这些事件从安全日志(注意需要管理员权限),然后显示出所有错误登陆信息。

# requires Admin privileges!

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 $time"

}

}

catch

{

if ($_.CategoryInfo.Category -eq 'ObjectNotFound')

{

Write-Host "No logon failures found." -ForegroundColor Green

}

else

{

Write-Warning "Error occured: $_"

}

}

}

注意这个函数也可以远程操作,使用-ComputerName参数去查询远程的电脑. 此时目标的电脑需要开启Remote Registry服务和具有它的本地管理员的权限。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: