I’m working on a simple script to read a log file, convert the latest reboot item flagged in said log file and convert it to a date object so I can compare it to another date object.
I’ve spent hours trying to troubleshoot this and just kept running into various roadblocks. The inherit [datetime] functionality doesn’t appear to be able to read my date string.
Code is attached, any input would be greatly appreciated.
Select-String <path to log file> -pattern <text to find> | Select-Object LineNumber, Line -Last 1 $GetLatestReboot = Get-Content $env:TemptextfileIdumpedOutputTo $LatestReboot = $GetLatestReboot | Select-String -Pattern '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].[0-9][0-9]:[0-9][0-9]:[0-9][0-9]' | Foreach-Object {$_.Matches} | Select-Object Value $LatestReboot = [datetime]$LatestReboot
submitted by /u/kareltehrobot
[link] [comments]
The post Help with string to date conversion appeared first on How to Code .NET.