I am working on a powershell script that is working fine for other string search but not this one. I was hoping to get help why
Power shell script construct is here:
$file = "C:\temp\test.log" $ConnectionReset = Get-Content $file | Select-String "connection read failed" -SimpleMatch | select -expand line | foreach { if($_ -match '(.+)java.lang.OutOfMemoryError(.+)'){ new-object psobject -Property @{ Date = [datetime]$matches[1].trim('#<').split("CDT>")[0] }| where {$_.Date -gt (Get-Date).AddMinutes(-15)} } } If ($ConnectionReset){ foreach ($line in $ConnectionReset){ # Send-MailMessage -From "xxx <test@gmail.com>" -Subject "Error" -To "XYZ <test@gmail.com>", -SmtpServer smtp.test.com }}
Line of log to parse out this error is here:
####<Sep 17, 2019 11:17:17 AM CDT> <Error> <Socket> <xx> <HFMWeb0> <ExecuteThread: '2' for queue: 'weblogic.socket.Muxer'> <<WLS Kernel>> <> <> <1568737037159> <BEA-000421> <Uncaught Throwable in processSocketsjava.lang.OutOfMemoryError: PermGen space.
java.lang.OutOfMemoryError: PermGen space
>
This is the error i am getting:
Cannot convert value " java.lang." to type "System.DateTime". Error: "The string was not recognized as a valid DateTime. There is an unknown word starting at index 1."At line:9 char:15
+ new-object psobject -Property @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvalidCastParseTargetInvocationWithFormatProvider