我想找出哪个用户、IP、工作站名称远程连接到工作站。这可以在事件日志 eventid 4624 logontype 10(远程交互,例如 rdp)中看到。当这种情况发生时,我需要消息字段中的一些数据,但只是一些而不是全部。
Get-WinEvent -FilterHashtable @{Path="c:\temp\raw_data\SavedSecurity.evtx";} |Where {($_.id -eq "4624" -and $_.properties[8].value -in 10)} |Select-Object -Property TimeCreated, Message |pause
我知道我可以使用提供的代码获取大量数据,还有消息字段中的远程 IP、远程工作站名称、远程用户 ID。
挑战来了:
我只想some来自消息字段的数据:
TargetUserName testuser
TargetDomainName testlab.internal
TargetLogonId 0xb6f45e
LogonType 7
WorkstationName testclientwin7
IpAddress 127.0.0.1
IpPort 64372
Message: Successful Login
有什么想法如何将它们(仅此字段,而不是其他字段)写入标题名称与所选数据项相同的 csv 文件吗?
thanks
peter
有什么想法如何将它们(仅此字段,而不是其他字段)写入标题名称与所选数据项相同的 csv 文件吗?
Plenty!
这是最安全的(尽管可能最不明显) - 使用EventPropertySelector https://msdn.microsoft.com/en-us/library/system.diagnostics.eventing.reader.eventlogpropertyselector.eventlogpropertyselector(v=vs.110).aspx!
Get-WinEvent -FilterHashtable @{Path="c:\temp\raw_data\SavedSecurity.evtx";} |Where {($_.id -eq "4624" -and $_.properties[8].value -in 10)} |%{
$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,$IPAddres,$Port = $_.GetPropertyValues($PropertySelector)
New-Object psobject -Property @{
Message = $_.Message
UserName = $UserName
Domain = $Domain
LogonId = $LogonId
LogonType = $LogonType
ComputerName = $ComputerName
IPAddres = $IPAddres
Port = $Port
TimeCreated = $_.TimeCreated
}
}
在上面的代码片段中,我们使用 XPath 位置选择器来获取相关的Data
事件的 XML 结构中的节点。如果其中任何一个不存在,则相应的变量将只是一个空字符串
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)