2017-02-09 2 views
0

目的:特定のコンピュータから最終日のイベントログを取得し、メッセージセクションを参照して特定のIPに基づいてデータをフィルタリングする(最初)スクリプトを作成し、開始する項目特定のキーワードを指定してHTMLに出力します。イベントログレコードのフィルタリング/マッチング

コード:

$fileDate = (Get-Date -Format ddMMyyyy) + ".html" 
$EventGrab = Invoke-Command { 
    Get-EventLog -LogName Security -After (Get-Date).AddDays(-1) -EntryType FailureAudit 
} -ComputerName whatever 
$EventGrab | 
    Sort-Object -Property TimeWritten -Descending | 
    Select-String -InputObject {$_.TimeWritten,$_.message} -Pattern "10.1.2.13" | 
    ConvertTo-Html | 
    Out-File C:\$fileDate 

ラフステップ:

  1. 日付でファイルを作成します。
  2. 過去24時間以内にFailureAuditのセキュリティログからイベントログを取得します。
  3. メッセージセクションで上記のパターン(デバイス)を確認してください。
  4. 問題ステップ3と4の間である1

ステップからの日付のファイルにHTML出力に変換します。私は、メッセージフィールドを取って特定の構文(例:LTC)を探して、それがHTMLファイルに見つかった場合にそのデータを出力するだけで、ステップ3の後でメッセージを再びフィルタリングする必要があります。

私はその別のSelect-Stringなどとは思っていますが、それは分かりません。

Select-Stringセクション@)入力例:唯一のアカウント名はhost/LTC<whatever>なるように変更

上:出力予想

02/08/2017 15:51:57 Network Policy Server denied access to a user. 
Contact the Network Policy Server administrator for more information. 
User: 
Security ID:     S-1-0-0 
Account Name:     <scrubbed> 
Account Domain:     <scrubbed> 
Fully Qualified Account Name: <scrubbed> 

Client Machine: 
Security ID:     S-1-0-0 
Account Name:     - 
Fully Qualified Account Name: - 
OS-Version:      - 
Called Station Identifier:  00-1B-53-41-5A-57 
Calling Station Identifier:  F8-CA-B8-57-1A-9B 

NAS: 
NAS IPv4 Address:    10.1.2.13 
NAS IPv6 Address:    - 
NAS Identifier:     - 
NAS Port-Type:     Ethernet 
NAS Port:      50324 

RADIUS Client: 
Client Friendly Name:   <scrubbed> 
Client IP Address:    10.1.2.13 

Authentication Details: 
Connection Request Policy Name: <scrubbed> 
Network Policy Name:   - 
Authentication Provider:  Windows 
Authentication Server:   <scrubbed> 
Authentication Type:   PEAP 
EAP Type:      Microsoft: Secured password (EAP-MSCHAP v2) 
Account Session Identifier:    - 
Logging Results:    Accounting information was written to the local log file. 
Reason Code:     8 
Reason:       The specified user account does not exist. 

。メッセージから文字列を抽出するためのレコードとSelect-Stringをフィルタリングするための

答えて

0

使用Where-Object

$EventGrab | 
    Sort-Object -Property TimeWritten -Descending | 
    Where-Object { 
     $_.Message -like '*10.1.2.13*' -and 
     $_.Message -like '*LTC*' 
    } | 
    Select-Object TimeWritten, @{n='Account';e={ 
     Select-String -InputObject $_.Message -Pattern 'Account Name:\s+(.*LTC.*)' | 
      Select-Object -Expand Matches | 
      ForEach-Object { $_.Groups[1].Value } 
    }} | 
    ConvertTo-Html | 
    Out-File C:\$fileDate 
+0

うーん。それは適切に機能していないように見えました(データ出力が得られません)。私はそれを間違って説明したかもしれないと思う、または私は何かが欠けている。 EventGrabの$ _。Messageデータでは、そのMessageフィールドに情報の束が戻ってきます.10.1.2.13かLTCのいずれかの膨大な量のデータの中で一致するようにしていますが、 '10 .1.2.13 'および/または' LTC 'が巨大なメッセージ内の文字列の一部ではなく文字列であることを探しているのかどうか疑問に思っています。 – elderusr07

+0

質問を編集し、サンプルの入力と出力を提供してください。 –

+0

一部の入出力が追加されました。 – elderusr07

関連する問題