Just a quick off the cuff and building off of what Dangph started but the triple scan is probably killing performance. $Scriptdone = $Validate | Where-Object {$_ -match $Scriptcompletedsuccess} $Updatedone = $Validate | where-object {$_ -match $Updatecomplete} $Failed = $Validate | Where-Object {$_ -match $FailedValidaton} Each one is reading through the entire file to find one thing. One route you can try out is using a foreach(You can shorthand it with % as I'll do below) and a switch. $size = $array.Length #Assumes there's only one line that will match a given regex per file #If not, it'll add duplicates which can be stripped at the end with an $array | sort -unique $validate |% { switch -regex($_){ $Scriptcompletedsuccess {$array += "$IDNumber, $Good1"; break} $updatecomplete {$array += "$IDNumber, $Good2"; break} $Failedvalidation {$array += "$IDNumber, $Fail1"; break} default {} } #Checks to see if array has grown, if it hasn't, no matches were found #Bit hacky and there's probably a better way to do it. if($size -eq $array.length){ $array += -join ("$IDNumber",', ',"$Fail2") }