bibi92
asked on
get errors on log
Hello,
dly_test.log contains :
21/05/2021 00:56:56 ERR1014 Une erreur s'est produite.
01/06/2021 00:22:10 ERR1016 Une interruption s'est produite.
04/06/2021 11:40:15 ERR1012 Le planificateur a été stoppé
I want to get errors during $LDays = 3 :
$Time = (Get-Date).AddDays(-$LDays).ToString('dd/MM/yyyy hh:mm:ss')
LogPath = "C:\TEMP\Log"
$Log = Get-ChildItem -path $LogPath -recurse -include dly_test.log
$ListError = 'ERR1014','ERR1016','ERR1012','ERR1011','ERR1013'
$Error = Get-Content -Path $Log|
Where-Object { $_ -contains $ListError -and ($_ -split ' ')[0] -gt $Time }
Thank you
Regards
dly_test.log contains :
21/05/2021 00:56:56 ERR1014 Une erreur s'est produite.
01/06/2021 00:22:10 ERR1016 Une interruption s'est produite.
04/06/2021 11:40:15 ERR1012 Le planificateur a été stoppé
I want to get errors during $LDays = 3 :
$Time = (Get-Date).AddDays(-$LDays).ToString('dd/MM/yyyy hh:mm:ss')
LogPath = "C:\TEMP\Log"
$Log = Get-ChildItem -path $LogPath -recurse -include dly_test.log
$ListError = 'ERR1014','ERR1016','ERR1012','ERR1011','ERR1013'
$Error = Get-Content -Path $Log|
Where-Object { $_ -contains $ListError -and ($_ -split ' ')[0] -gt $Time }
Thank you
Regards
ASKER
Hello,
Below error is returned :
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
At line:2 char:16
+ ... re-Object { $_ -match $ListError -join " " -and [datetime]::Parse ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
Thank you
regards
Below error is returned :
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
At line:2 char:16
+ ... re-Object { $_ -match $ListError -join " " -and [datetime]::Parse ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
Thank you
regards
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
does your error log contains over details that particularly not starting with a log date time? the script provided try to parse the date time for the first 2 array items delimited with space.
ASKER
No the error log not contains details not starting with a log date time. But when I try without -join "|" -and [datetime]::ParseExact((($_ -split ' ')[0] + " " + ($_ -split ' ')[1]), "dd/MM/yyyy hh:mm:ss", $null) -gt $Time
$Errorz is null so maybe a problem with the list.
Thank you
$Errorz is null so maybe a problem with the list.
Thank you
can you share the content of line 2 ?
ASKER
Hello,
At line:2 char:16
+ ... re-Object { $_ -match $ListError -join "|" -and [datetime]::ParseExac ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
At line:2 char:16
+ ... re-Object { $_ -match $ListError -join "|" -and [datetime]::ParseExac ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
Thank you
$LDays = 3
$Time = (Get-Date).AddDays(-$LDays)
$LogPath = "C:\TEMP\Log"
$Log = Get-ChildItem -path $LogPath -recurse -include dly_test.log
$ListError = 'ERR1014','ERR1016','ERR1012','ERR1011','ERR1013'
$Errorz = Get-Content -Path $Log |
Where-Object { $_ -match $ListError -join "|" -and [datetime]::ParseExact((($_ -split ' ')[0] + " " + ($_ -split ' ')[1]), "dd/MM/yyyy hh:mm:ss", $null) -gt $Time }
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."At line:2 char:16
+ ... re-Object { $_ -match $ListError -join "|" -and [datetime]::ParseExac ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
At line:2 char:16
+ ... re-Object { $_ -match $ListError -join "|" -and [datetime]::ParseExac ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
Thank you
sorry, I mean the line 2 of file : dly_test.log
ASKER
04/06/2021 00:56:56 ERR1013 Une interruption s'est produite
Thank you
Best regards
Thank you
Best regards
found the issue on 24 hours format, so try use this instead:
$LDays = 3
$Time = (Get-Date).AddDays(-$LDays)
$LogPath = "C:\TEMP\Log"
$Log = Get-ChildItem -path $LogPath -recurse -include dly_test.log
$ListError = 'ERR1014','ERR1016','ERR1012','ERR1011','ERR1013'
$Errorz = Get-Content -Path $Log |
Where-Object { $_ -match $ListError -join "|" -and [datetime]::ParseExact((($_ -split ' ')[0] + " " + ($_ -split ' ')[1]), "dd/MM/yyyy HH:mm:ss", $null) -gt $Time }
ASKER
Hello
Same error
Thank you
Same error
Thank you
ASKER
The problem is on $ListError, If I change $_ -match 'ERR1013'
The result is returned regardless of the date but I don't see what I can modify on Where-Object :
04/06/2021 00:56:56 ERR1013 Une interruption s'est produite
$LDays = 3
$Time = (Get-Date).AddDays(-$LDays)
$LogPath = "C:\TEMP\Log"
$Log = Get-ChildItem -path $LogPath -recurse -include dly_test.log
$ListError = 'ERR1014','ERR1016','ERR1012','ERR1011','ERR1013'
$Errorz = Get-Content -Path $Log |
Where-Object { $_ -match 'ERR1013' -and [datetime]::ParseExact((($_ -split ' ')[0] + " " + ($_ -split ' ')[1]), "dd/MM/yyyy HH:mm:ss", $null) -gt $Time }
The result is returned regardless of the date but I don't see what I can modify on Where-Object :
04/06/2021 00:56:56 ERR1013 Une interruption s'est produite
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No I confirm it works I reset powershell session
Thank you for your support
Thank you for your support
Open in new window