public/Event/Get-SportData.ps1
using module '..\..\modules\Enums.psm1' using module '..\..\modules\Helper\DateTimeHelper.psm1' using module '..\..\modules\Helper\StringHelper.psm1' using module '..\..\modules\Helper\ObjectHelper.psm1' using module '..\..\modules\Session.psd1' function Get-SportData{ [CmdletBinding()] [Alias('gsd')] param( [Parameter(Mandatory=$true)] [SOURCE] $source, [ValidateSet('first', 'last', 'all')] [string] $display = 'first' ) #region Init if ([Session]::activeSessions.Count -eq 0){ Write-Error 'There is no active session. Import audit logs before they are analyzed.' return } if (-not [Session]::getCurrent().canRead($source)){ Write-Error 'Background jobs are still active, try later.' return } $hasReturn = $false $logFile = [Session]::getCurrent().auditLogFile $processor = [ProcessorFactory]::getBySource($source) $totalLines = $logFile.AssignFile($source) $count=0; $progressMessage='Reading sport data...' #endregion while (-not $logFile.EOF()) { $line = $logFile.ReadLine() $processor.ProcessMessage($line) $processor.ProcessEvent($line, $true) if ($processor.message.event) { if ($display -eq 'first') { $hasReturn = $true; break } if ($display -eq 'all') { $currSportData = [ObjectHelper]::CombineObject($processor.message.event.sportData, $prevSportData) if ($currSportData) { $prevSportData = $currSportData.Copy()} } $hasReturn = $true } $count++ $percentage = 100 * $count / $totalLines Write-Progress -Activity $progressMessage -PercentComplete $percentage } if ($hasReturn) { Write-Output $processor.message.event.sportData } elseif ($display -eq 'all' -and $prevSportData) { Write-Output $prevSportData } Write-Progress -Activity $progressMessage -Completed if (-not $hasReturn){ Write-Host 'There is no output for the selected filter(s)!' -ForegroundColor Red } } |