Удобный анализ логов

Понадобилось проанализировать логфайл установленных на сервер обновлений HP, минут за 15-20 наклепал такую парсилку:

param ([string]$file = "c:\CPQSYSTEM\log\cpqsetup.log")
switch -regex (get-content $file) 
{
	"Setup Session Beginning\:? +(.+)"{
		$o = New-Object psobject
		$o | add-member noteproperty Date $matches[1]
		$o | add-member noteproperty Info ""
		continue
	}
	"----------" {continue}
	"End Session" {$o; continue}
	"Command Line Parameters Given: (.+)" {$o | add-member noteproperty Params $matches[1]; continue}
	"Current Version\:?(.+)" {$o | add-member noteproperty PrevVersion $matches[1].trim(); continue}
	"Name: +(.+)" {$o | add-member noteproperty Name $matches[1]; continue}
	"New version: +(.+)" {$o | add-member noteproperty NewVersion $matches[1]; continue}
	"The operation was successful" {$o | add-member noteproperty Result "Success"; continue}
	"Setup will not be complete until the system is rebooted" {$o | add-member noteproperty Result "RebootNeeded"; continue}
	"Installation will not continue" {$o | add-member noteproperty Result "NotInstalled"; continue}
	"^  - (.+)"{$o | add-member noteproperty Action $matches[1]; continue}
	{$_.trim() -ne ""} {$o.Info+="$_`n"; continue}
}

Это всё надо поместить в файл, например Get-HPInstallLog.ps1
Далее для того чтобы например посмотреть обновления установленные в определённую дату и их версии:

PS D:\PowerShell> $hpupdates = .\Get-HPInstallLog.ps1
PS D:\PowerShell> $hpupdates | 
>>where {$_.date -like "14.03.2007*" -and $_.result -ne "NotInstalled"} | 
>>Format-Table name, *version, result -AutoSize

Name                                                       NewVersion     PrevVersion            Result
----                                                       ----------     -----------            ------
HP ProLiant iLO Advanced and Enhanced System Management    5.42.0.0       5.41.0.0               RebootNeeded
HP ProLiant Smart Array 5x and 6x Controller Driver for    5.74.0.32      5.72.0.32              RebootNeeded
HP ProLiant Remote Monitor Service for Windows             5.11.1.0       5.10.0.0               Success
HP ProLiant Integrated Lights-Out Management Interface     1.10.0.0       1.9.2195.0             RebootNeeded
HP ProLiant ATI RAGE XL Video Controller Driver for        5.10.2600.6024 5.10.2600.6013         RebootNeeded
HP ProLiant Array Configuration Utility for Windows        7.70.12.0      7.60.18.0              Success
HP ProLiant Array Diagnostics Utility for Windows          7.70.12.0      7.60.18.0              Success
HP ProLiant Array Configuration Utility (CLI) for Windows  7.70.12.0      7.60.19.0              Success
HP Protect Your Data Information and Application Downloads 1.0.3.0        1.0.2.0                Success
...
Опубликовано в PowerShell. Комментарии к записи Удобный анализ логов отключены
%d такие блоггеры, как: