How can I read only the last two rows of a .log file? The following script reads the full .log file which returns an incorrect status. For my particular case the string returning the correct status per .log file is written in the last two rows.
function Get-Status($file) {
if (Select-String -Quiet 'Finished with errors' $_.FullName) {
return "ERROR"
} elseif (Select-String -Quiet 'Finished with warnings' $_.FullName) {
return "WARNING"
} elseif (Select-String -Quiet 'Finished.' $_.FullName) {
return "SUCCESS"
} else {
return "FAILED"
}
}
Get-ChildItem C:\logfolder\*.log | % {
[PSCustomObject] @{
Name = $_.Name;
Date = $_.LastWriteTime;
Status = Get-Status($_.FullName)]
}
}