2017-09-01 10 views
0

Regexを使用する代わりに、イベントログエントリのテキストメッセージブロックのサブ文字列を取得できますか?イベントログエントリのメッセージブロック値を取得する

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

私のコードのこの部分の下にあるテキストを返します:私は右の値のみが欲しい

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 

これは、テキストのブロックがどのように見えるかです

$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 

答えて

0

どのようにログデータを抽出していますか? Get-WinEventを使用するときに使用できないReplacementStringsフィールドを探しています。

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

し、それらが動作しない場合は、この最も確実でしょう:

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]など

関連する問題