Created
March 9, 2016 18:16
-
-
Save iainbrighton/42851be19637c44c3a96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Measure-Command { | |
$SAMLogArrayList = New-Object -TypeName System.Collections.ArrayList -ArgumentList @() | |
$NumOfFiles = (Get-ChildItem -file $directory).count | |
$counter = 1 | |
Foreach($file in (Get-ChildItem -file $directory).FullName) { | |
$PercentComplete = (($counter / $NumOfFiles) * 100) | |
$PercentComplete = [math]::Round($PercentComplete, 2) | |
Write-Progress -id 1 -Activity "Reading Files." -PercentComplete $PercentComplete -CurrentOperation "$($PercentComplete)% complete" -Status "Please wait" | |
$fileContent = Get-Content $file | |
for ($i = 0; $i -lt $fileContent.Count; $i++) | |
{ | |
if (($i -gt 0) -and ($i % 10 -eq 0)) { | |
$FilePercentComplete = (($i / $fileContent.Count) * 100) | |
$FilePercentComplete = [math]::Round($FilePercentComplete, 2) | |
Write-Progress -id 2 -ParentId 1 -Activity "Processing file $($file)" -PercentComplete $FilePercentComplete -CurrentOperation "$($FilePercentComplete)%" -Status "Reading file" | |
} | |
$null = $fileContent[$i] -match $regex_expression | |
If($Matches){ | |
[ref] $null = $SAMLogArrayList.Add([pscustomobject]@{ | |
'date'= "$($Matches[1])" | |
'time'= "$($Matches[2])" | |
'Schedule_Name'= "$($Matches[3])" | |
'Job_Name'= "$($Matches[4])" | |
'Job_ID'= "$($Matches[5])" | |
'Status_Message'="$($Matches[6])" | |
}) | |
Remove-Variable Matches | |
} | |
} | |
} | |
} | |
$SAMLogArray = $SAMLogArrayList.ToArray(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment