Author Posts

January 1, 2012 at 12:00 am

by Divad at 2012-10-07 04:32:17

I have a log CSV file

7:00:13; Event A;
7:01:05; Event C;
7:05:00; Event A;
7:13:05; Event B;
7:23:20; Event C;

now I want all events starting from 7:01:05 and 10 minutes ahead. How do I get that?
I suppose I shall use Get-date but how to make comparison ?

by HeSitated at 2012-10-07 07:15:39

Try something like:

$csv = "7:00:13; Event A;
7:01:05; Event C;
7:05:00; Event A;
7:13:05; Event B;
7:23:20; Event C;"

$events = ConvertFrom-Csv $csv -Header "Time", "Event" -delimiter ";"

$startTime = [System.DateTime]"7:01:05"
$endTime = $startTime.AddMinutes(10)

foreach($event in $events)
{
$time = [System.DateTime] $event.Time
if($time -ge $startTime -And $time -lt $endTime )
{
"{0} --> {1}" -f $time, $event.Event
}
}

Use Import-Csv to read from file instead of variable.

by Divad at 2012-10-07 07:47:53

Thanks