我正在尝试过滤事件日志,除了查询中的消息字段外,它工作正常。消息字段中有很多描述性文本。我只想要它的第一句话,因为这是重要的,其余的都是垃圾。
消息字段的示例内容:
An account was successfully logged on.
Subject:
Security ID: SYSTEM
Account Name: WIN-R9H529RIO4Y$
Account Domain: WORKGROUP
Logon ID: 0x3e7
Logon Type:10
New Logon:
Security ID: WIN-R9H529RIO4Y\Administrator
Account Name: Administrator
Account Domain: WIN-R9H529RIO4Y
Logon ID: 0x19f4c
Logon GUID: {00000000-0000-0000-0000-000000000000}
Process Information:
Process ID: 0x4c0
Process Name: C:\Windows\System32\winlogon.exe
Network Information:
Workstation Name: WIN-R9H529RIO4Y
Source Network Address: 10.42.42.211
Source Port: 1181
Detailed Authentication Information:
Logon Process: User32
Authentication Package: Negotiate
Transited Services: -
Package Name (NTLM only): -
Key Length: 0
This event is generated when a logon session is created. It is generated on the computer that was accessed.
The subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe.
The logon type field indicates the kind of logon that occurred. The most common types are 2 (interactive) and 3 (network).
The New Logon fields indicate the account for whom the new logon was created, i.e. the account that was logged on.
The network fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases.
The authentication information fields provide detailed information about this specific logon request.
The authentication information fields provide detailed information about this specific logon request.
•Logon GUID is a unique identifier that can be used to correlate this event with a KDC event.
•Transited services indicate which intermediate services have participated in this logon request.
•Package name indicates which sub-protocol was used among the NTLM protocols.
•Key length indicates the length of the generated session key. This will be 0 if no session key was requested.
我只想要“一个帐户已成功登录”。
我已经尝试过(但失败了):
Get-WinEvent -FilterHashtable @{Path="c:\temp\export.evtx";} |
Where-Object {($_.id -eq "4624" -and $_.properties[8].value -in 2,3,10) -or ($_.id -eq "4625") -or ($_.id -eq "4800")} |
ForEach-Object{
$SelectorStrings = [string[]]@(
'Event/EventData/Data[@Name="TargetUserName"]',
'Event/EventData/Data[@Name="TargetDomainName"]',
'Event/EventData/Data[@Name="TargetLogonId"]',
'Event/EventData/Data[@Name="LogonType"]',
'Event/EventData/Data[@Name="WorkstationName"]',
'Event/EventData/Data[@Name="IpAddress"]',
'Event/EventData/Data[@Name="IpPort"]'
)
$PropertySelector = [System.Diagnostics.Eventing.Reader.EventLogPropertySelector]::new($SelectorStrings)
$UserName,$Domain,$LogonId,$LogonType,$ComputerName,$IPAddress,$Port = $_.GetPropertyValues($PropertySelector)
[PSCustomObject]@{
TimeCreated = $_.TimeCreated
UserName = $UserName
Domain = $Domain
LogonId = $LogonId
LogonType = $LogonType
ComputerName = $ComputerName
IPAddres = $IPAddres
Port = $Port
Message = ($_.Message).split(".")
}|Export-Csv -NoTypeInformation -Force -Encoding UTF8 -Path 'c:\temp\exportencoding2.csv' -Append
}
结果是:
"TimeCreated","UserName","Domain","LogonId","LogonType","ComputerName","IPAddres","Port","Message"
"04.12.2017 13:56:34","Testuser","lab.internal",,"7","AssetWin7PC","127.0.0.1","0","System.String[]"
输出是“System.String[]”,但它应该是第一句话。