我试图创build一个脚本,在过去的24小时内拉动失败的日志尝试某些事件,但我不知道如何拉出帐户信息。 用户一直是空的,所以信息是空白的,但是当我在常规标签中看到我可以看到“帐户信息”。
我想拉和添加什么它显示在“事件数据”是TargetUserName下的XML视图。 我怎样才能做到这一点? 我到目前为止工作正常,但我需要的用户名信息和我的脚本拉什么总是空白。
系统 – Windows Server 2008 R2日志我从过去24小时的事件ID 4625,4768,4771,4772是安全日志。
我的代码:
get-eventlog Security 4625,4768,4771,4772 -after ((get-date).addDays(-1))| export-csv
尝试以下操作,它将从事件消息中提取TargetUserName,并将其作为新列添加到原始事件中。 您现在可以将其导出到c:\ temp \ yourlog.csv或任何您需要的位置。
get-eventlog Security 4625,4768,4771,4772 -after ((get-date).addDays(-1)) | % { $TargetUserName = $_.message.split("`n") | Select-String "Account Name:"; $_ | Add-Member -MemberType NoteProperty -Name TargetUserName -Value $TargetUserName[0]; $_ } | Export-CSV "c:\temp\yourlog.csv" -notypeinformation
因为事件返回一个XML对象,所以你必须parsing这个来获取用户信息。 我使用这个来通过任务计划程序抓取locking的账户,并将XML信息作为文本发送给我,以便我可以查看它。 它不回答你的问题,但可能会为你解决方法。 我更愿意立即知道事件,而不是事后的方式。 有一个错误,如果它发生,同时还有另一个事件,脚本只看最近的事件。 所以记住这一点。 对于我的设置,每天可能会有一个,这很好。
$5MinutesAgo = [DateTime]::Now.AddMinutes(-5) $messageParameters = @{ Subject = "User Account Locked/Unlocked on VADS01" Body = Get-EventLog "Security" | Where {$5MinutesAgo -le $_.TimeWritten -and ($_.eventid -eq 4740 -or $_.eventid -eq 4767)} | Format-List | Out-String From = "[email protected]" To = "[email protected]" SmtpServer = "smtp01.domain.com" } Send-MailMessage @messageParameters