2013-01-31 3 views
1

Windows 이벤트 로그를 프로덕션 환경에서 CSV로 주기적으로 내보내도록 요구했습니다.Windows 이벤트 로그를 CSV-Powershell 2.0으로 내보내기

나는 이벤트가 필요한 기계 목록과 검색해야하는 이벤트 ID 목록이 들어있는 간단한 XML 구성 파일을 가지고 있습니다.

여기에서 차례로 각 컴퓨터 이름을 반복하고 각 이벤트 ID를 통해 로그를 검색 한 다음 CSV로 내 보냅니다. 실행 당 컴퓨터 당 하나의 CSV를 원합니다. 내 모든 변수의 PS 명령 난 CSV 각 시간을 추가 할 수없는거야 하나의 이벤트 ID

foreach ($machine in $config.Configuration.Machines.Machine) 
{ 
    $csvname=$outputlocation + $machine.Value + "_" + $datestring + ".csv" 

    foreach ($eventid in $config.Configuration.EventIds.EventId) 
    { 
     Get-WinEvent -ComputerName $machine.Value -ErrorAction SilentlyContinue -FilterHashTable @{Logname='Security';ID=$eventid.Value} | where {$_.TimeCreated -gt $lastexecutiondate} | export-csv -NoClobber -append $csvname 
    } 
} 

Execpt, PS 2.0에 대한 로그를 검색하는 것은 매우 간단하다을 일하면

분명히 이 기능을 지원하지 않습니다. 한 번에 모든 이벤트 ID를 추출해 보았습니다. 그러나 이것은 약간 길어진 것 같아서 이제 설정 파일을 사용할 수있게되었습니다.하지만 PowerShell을 처음 접해 보니 많은 행운이 없었습니다.

또한 여러 개의 LogNames (시스템, 보안 및 응용 프로그램)를 지정해야하며 같은 문장을 3 번 반복하는 대신 하나의 명령문을 실행하고 appe하지만이 작업을 수행하는 방법은 확실하지 않습니다.

불행히도이 시점에서 Google은 나를 서클에서 운영하고 있습니다.

답변

1

다음은 선택 이벤트 로그의 이전 24 시간 이벤트를 내보낼 수 있도록 함께 선택한 항목입니다. 예약 된 작업을 만들어서 매일 가져 오도록하겠습니다. 이 다른 사람 도움 희망 ... 내가 보안 로그 내보내기 실패 이유는 무엇입니까

$eventLogNames = "Application", "Security", "System", "Windows PowerShell" 
$startDate = Get-Date 
$startDate = $startDate.addDays(-1).addMinutes(-15) 

function GetMilliseconds($date) 
{ 
    $ts = New-TimeSpan -Start $date -End (Get-Date) 
    [math]::Round($ts.TotalMilliseconds) 
} 

$serverName = get-content env:computername 
$serverIP = gwmi Win32_NetworkAdapterConfiguration | 
    Where { $_.IPAddress } | # filter the objects where an address actually exists 
    Select -Expand IPAddress | # retrieve only the property *value* 
    Where { $_ -notlike '*:*' } 
$fileNameDate = Get-Date -format yyyyMMddhhmm 
$endDate = Get-Date 
$startTime = GetMilliseconds($startDate) 
$endTime = GetMilliseconds($endDate) 

foreach ($eventLogName in $eventLogNames) 
{ 
    Write-Host "Processing Log: " $eventLogName 

<# - Remove comment to create csv version of log files 
    $csvFile = $fileNameDate + "_" + $serverIP +"_" + $eventLogName + ".csv" 
    Write-Host "Creating CSV Log: " $csvFile 
    Get-EventLog -LogName $eventLogName -ComputerName $serverName -After $startDate -ErrorAction  SilentlyContinue | Sort MachineName, TimeWritten | Select MachineName, Source, TimeWritten, EventID, EntryType, Message | Export-CSV $csvFile #ConvertTo-CSV #Format-Table -Wrap -Property Source, TimeWritten, EventID, EntryType, Message -Autosize -NoTypeInformation 
#> 
    $evtxFile = $fileNameDate + "_" + $serverIP + "_" + $eventLogName + ".evtx" 
    Write-Host "Creating EVTX Log: " $evtxFile 
    wevtutil epl $eventLogName $evtxFile /q:"*[System[TimeCreated[timediff(@SystemTime) >= $endTime] and TimeCreated[timediff(@SystemTime) <= $startTime]]]" 
} 
0

. 지정된 쿼리가 유효하지 않습니다. 나는 이벤트 로그 (시스템, 응용 프로그램 등)의 각 유형에 대해 이것을 얻습니다. 이것은 evtx 내보내기에만 발생합니다. 나는 CSV 파일을 얻는다 .` ...

+0

이것은 질문이지만, 제기 된 질문에 대한 대답이 아닙니다. 새로운 질문을하고 관련성이있는 경우이 질문에 연결하는 것을 고려하십시오. – JamesT

관련 문제