Skip to content

Instantly share code, notes, and snippets.

@iainbrighton
Created March 9, 2016 18:04
Show Gist options
  • Save iainbrighton/8d8dd04b019674eb7a6d to your computer and use it in GitHub Desktop.
Save iainbrighton/8d8dd04b019674eb7a6d to your computer and use it in GitHub Desktop.
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"
$LinesInFile = (Get-Content $file).count
$x = 1
Get-Content $file | ForEach-Object{
$FilePercentComplete = (($x / $LinesInFile) * 100)
$FilePercentComplete = [math]::Round($FilePercentComplete, 2)
if (($FilePercentComplete % 10) -eq 0) {
Write-Progress -id 2 -ParentId 1 -Activity "Processing file $($file)" -PercentComplete $FilePercentComplete -CurrentOperation "$($FilePercentComplete)%" -Status "Reading file"
}
$x += 1
$null = $_ -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
}
}
$counter += 1
}
}
$SAMLogArray = $SAMLogArrayList.ToArray();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment