I'm working with a log file and I want to filter messages that were added in the last 5 minutes, I don't understand why the [datetime]::ParseExact method returns error on this format
LOG FORMAT
18-08-2021 12:00:00 Debug 127.0.0.1 hello
CODE
$nowTime = (Get-Date).AddMinutes(-5)
Get-Content -Path "" |
Where-Object { $_ -match "^(\d{2}-\d{2}-\d{4}\t\d{2}:\d{2}:\d{2})" } |
Where-Object { [datetime]::ParseExact($matches[1], "dd-MM-yyyy `tHH:mm:ss", $null) -gt $nowTime } |
ForEach-Object {
Write-Output $_
}
ERROR
"ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."