我正在为事件 4625 使用 get-winevent,因为我需要失败原因,它位于事件的 xml 字段中。
我尝试的第一件事是打印出所有希望的字段,失败原因在 xml 的数据路径中的某处可用,但没有成功。
我没有找到一种方法来使用 powershell 查询状态码 %%2313 以获取可读文本。
我做的最后一件事是过滤特定事件并自己在导出文件的自定义字段中写入状态消息。
我用这段代码来实现这一点:
Get-WinEvent -FilterHashtable @{Path="c:\temp\test.evtx";} -ErrorAction SilentlyContinue |
Where-Object {($_.id -eq "4625" -and $_.properties[9].value -in "%% 2313")}|ForEach-Object{
$SelectorStrings = [string[]]@(
'Event/EventData/Data[@Name="TargetUserName"]',
'Event/EventData/Data[@Name="TargetDomainName"]',
'Event/EventData/Data[@Name="WorkstationName"]',
'Event/EventData/Data[@Name="IpAddress"]',
'Event/EventData/Data[@Name="IpPort"]',
'Event/EventData/Data[@Name="LogonType"]',
'Event/EventData/Data[@Name="FailureReason"]',
'Event/EventData/Data[@Name="Remark"]'
)
$PropertySelector = [System.Diagnostics.Eventing.Reader.EventLogPropertySelector]::new($SelectorStrings)
$TargetUserName,$TargetDomainName,$WorkstationName,$IpAddress,$IpPort,$LogonType,$FailureReason,$Remark = $_.GetPropertyValues($PropertySelector)
$Remark ="Unbekannter Benutzername oder ungültiges Kennwort."
#Create the PSCustomObject from the given Fieldnames
[PSCustomObject]@{
TimeCreated = $_.TimeCreated
Id = $_.Id
UserName = $TargetUserName
Domain = $TargetDomainName
WorkstationName = $WorkstationName
IPAddress = $IpAddress
Port = $IpPort
LogonType = $LogonType
Message = ($_.Message).split(".")[0]
Remark = $Remark
FailureReason =$FailureReason
}
}|Export-Csv -NoTypeInformation -Force -Encoding UTF8 -Path 'c:\temp\failurereason.csv'
但是:它接缝我无法过滤 %%2313 作为属性值。不知道为什么。即使有引号之类的,也不要把任何事件弄出来。