Skip to main content
Arraylists
Source Link
Veskah
  • 111
  • 5

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")
}

Oh yeah, another performance boost (not sure how much of one though) would be changing the array into an ArrayList. They can append whereas the array resizes on each add.

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")
}

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")
}

Oh yeah, another performance boost (not sure how much of one though) would be changing the array into an ArrayList. They can append whereas the array resizes on each add.

Source Link
Veskah
  • 111
  • 5

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")
}