Compare yesterday date & current date from log file

I have a log file, I need compare previous date end time & current date end time (based on the system).
If the current end time does not find in the log, trigger an email.

If current end time finds in the log, attach the log.

Log details:

Data Start Time - 2018-02-18 22.30.00
Data End Time - 2018-02-19 00.55.50
Time taken for whole process - 8544

Data Start Time - 2018-02-19 22.30.00


$log = Get-ChildItem c:\opscripts\test\server01\test.log
$results = switch -Regex -File $log {
    'Data (Start|End) .*' {$Matches[0]}
    'Time taken for whole process.*' {$Matches[0]}


To compare dates and times you should convert them to DateTime objects or TimeSpan objects and compare them this way. Something like this could help you to start:

[datetime]::ParseExact(‘2018-02-18 22.30.00’, ‘yyyy-MM-dd’, $null)