EDIT:
Okay, I have made a few changes and it is going quicker, but still very sluggish.
function Get-MR4RES {
[CmdletBinding()]
param (
[Parameter(Position = 0,
Mandatory = $True)]
[ValidateNotNullorEmpty()]
[ValidateScript( {Test-Path -Path $_ -PathType 'Any'})]
[String]
$Files,
[Parameter(Position = 1,
Mandatory = $false)]
[String]
$CSVPath) # End Param
begin {
$Scriptcompletedsuccess = '.+Script\scompleted\ssuccessfully.+' # 3:44:15 End function called, Script completed successfully at 3:44:15 on Tue 07/03/2018
$Updatecomplete = '\w+\s+\:\s\[\d+\:\d+\:\d+\]\s+\w+\scomplete' # STATUS : [03:43:07] Update complete
$FailedValidaton = '.+check\sfail.+'
$Fail1 = 'Validation Failed'
$Fail2 = 'Update Failed'
$Good1 = 'Script completed'
$Good2 = 'Update completed'
$array = @('IDNumber, Results')
$counter = 0
$FileList = (Get-ChildItem -Path $Files -File -Filter "*.log").FullName
$Done = ''
} # End begin
process {
foreach ($File in $fileList) {
if ((Get-Item $Files) -is [System.IO.DirectoryInfo]) {
$counter++
Write-Progress -Activity 'Analyzing Files' -CurrentOperation $File -PercentComplete (($counter / $FileList.count) * 100)
}
$DriveIn = [System.IO.Path]::GetFileName("$File").split('-')[0]
$Failed = Select-String -Pattern $FailedValidaton -Path $File
if($Failed){
$Done = $Fail1
$array += -join ("$IDNumber",', ',"$Done")
}
else {
$Scriptdone = Select-String -Pattern $Scriptcompletedsuccess -Path $File
if($Scriptdone){
$Done = $Good1
$array += -join ("$IDNumber",', ',"$Done")
}
else {
$Updatedone = Select-String -Pattern $Updatecomplete -Path $File
if($Updatedone){
$Done = $Good2
$array += -join ("$IDNumber",', ',"$Done")
}
else {
$Done = $Fail2
$array += -join ("$IDNumber",', ',"$Done")
} # End of #Updatedone
}# End of #Scriptdone
}# End of #Failed
} # End of #foreach
} # End process section
End {
if ($PSBoundParameters.ContainsKey('CSVPath')) {
Add-Content -Path $CSVPath -Value $array -Encoding ascii
}
else {
Write-Output $array
} # End of else
} # End of the End
} # End of function