首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >事件日志条目消息块检索值

事件日志条目消息块检索值
EN

Stack Overflow用户
提问于 2017-09-01 19:45:54
回答 1查看 197关注 0票数 0

是否可以在事件日志条目的文本消息块中检索子字符串,而不是使用正则表达式?

这是文本块的样子:

代码语言:javascript
复制
Kerberos pre-authentication failed.

Account Information:
    Security ID:        HO\administrators$
    Account Name:       administrators$

Service Information:
    Service Name:       krbtgt/HO.FOSLTD.CO.ZA

Network Information:
    Client Address:     ::ffff:10.250.1.12
    Client Port:        51933

Additional Information:
    Ticket Options:     0x40000000
    Failure Code:       0x18
    Pre-Authentication Type:    2

我只想要下面右边的值:

代码语言:javascript
复制
Account Name 
Client Address, but with out the ::ffff:
Failure Code

我的这部分代码返回以下文本:

代码语言:javascript
复制
 $sSecurityID = $Item.SubString($Item.IndexOf("Account Information"))
 $sSecurityID = $sSecurityID.SubString($sSecurityID.IndexOf("Account Name"))
 $sSecurityID = $sSecurityID.TrimStart("Account Name:")
 $sSecurityID = $sSecurityID.Trim()

输出:

代码语言:javascript
复制
OrtheaE

Service Information:
    Service Name:       krbtgt/ho

Network Information:
    Client Address:     ::ffff:172.26.50.11
    Client Port:        20697

Additional Information:
    Ticket Options:     0x40810010
    Failure Code:       0x18
    Pre-Authentication Type:    2
EN

回答 1

Stack Overflow用户

发布于 2017-09-04 18:59:19

您是如何提取日志数据的?您正在寻找在使用Get-WinEvent时不可用的ReplacementStrings字段。

代码语言:javascript
复制
get-eventlog -computername dc-01 -logname security | ?{$_.eventid -eq "4674"} | 
select machinename,eventid,@{n='AccountName';e={$_.ReplacementStrings[1]}},entrytype,message | 
convertto-html | out-file c:\test.html

然后,如果这些都不起作用,这肯定会起作用:

代码语言:javascript
复制
Get-EventLog "Security" -before 4/10/2013 -InstanceId 4663 | % {
    New-Object psobject -Property @{
        Index = $_.Index
        TimeGenerated = $_.TimeGenerated
        "Account Name" = $_.ReplacementStrings[1]
        "Object Type" = $_.ReplacementStrings[5]
        "Object Name" = $_.ReplacementStrings[6]
    }
} | export-csv c:\export.csv -NoTypeInformation

您将看到所有值都按照它们在文本中显示的顺序出现在ReplacementStrings中。该消息中的第一个变量是“安全ID",因此它最有可能存储在$_.ReplacementStrings等文件中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45999589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档