troubleshooting Question

problem date format

Avatar of bibi92
bibi92Flag for France asked on
3 Comments1 Solution17 ViewsLast Modified:

How to modify the date format on the script depending fr or Us for resolve :
Could not compare "06/04/2021 11:41:15" to "30/05/2021 06:06:16". Error: "Cannot convert value "30/05/2021 06:06:16"
to type "System.DateTime". Error: "String was not recognized as a valid DateTime.""

Thank you

$Days = 3
$TimeFR  = (Get-Date).AddDays(-$Days).ToString("dd-MM-yyyy hh:mm:ss")
$TimeUS  = (Get-Date).AddDays(-$Days).ToString("MM-dd-yyyy hh:mm:ss")
$FormatUS = 'MM/dd/yyyy HH:mm:ss'
$FormatFR = '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'
If ( $value -eq 'computer')
  $Format = $FormatFR
  $ReferenceTime = $ReferenceTimeFR 
  $Format = $FormatUS
  $Time = $ReferenceTimeUS
$Errorz = Get-Content -Path $Log |
Where-Object { $_ -match 'ERR1013' -and [datetime]::ParseExact((($_ -split ' ')[0] + " " + ($_ -split ' ')[1]), $Format, $null) -gt $Time }

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros