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

时间:2017-09-01 11:45:54

标签: string powershell text event-log

而不是使用Regex,我可以在事件日志条目的文本消息块中检索子字符串吗?

这就是文本块的样子:

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

我只想要右边的值:

Account Name 
Client Address, but with out the ::ffff:
Failure Code

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

 $sSecurityID = $Item.SubString($Item.IndexOf("Account Information"))
 $sSecurityID = $sSecurityID.SubString($sSecurityID.IndexOf("Account Name"))
 $sSecurityID = $sSecurityID.TrimStart("Account Name:")
 $sSecurityID = $sSecurityID.Trim()

输出:

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

1 个答案:

答案 0 :(得分:0)

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

{{1}}

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

{{1}}

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