# Process log file with powershell.

I have a log file which lists each package that was run by an ETL process. This is roughly in the format attached... What I need is the powershell logic to iterate through this file and tell me the starttime and endtime of each package so I can calculate how long each took. Between each of the package start/end statements are a lot of logging but for now I dont care about this. Any ideas?

If you could provide code for this example I think I could adapt this to my specific problem, unfortunately I am unable to post the complete logfile - but for those that are in the know it is a standard format ETL log.

PackageStart,ETLJOB,13/04/2011 09:00:04

PackageEnd,ETLJOB,13/04/2011 09:00:04

###### Who is Participating?

Commented:
Here is my first try, update the path in line 2.
$taskdb = @{} Get-Content C:\ee\package.txt | ?{$_.trim()}| %{
$parts =$_.trim() -split ","
$type =$parts[0]
$name =$parts[1]
$time = [datetime]::ParseExact($parts[2],"dd\/MM\/yyyy hh:mm:ss",$null) if($type -eq "Packagestart"){
$taskdb.$name = @($time,$null,$null) } elseif($type -eq "PackageEnd" -and $taskdb.$name){
$taskdb.$name[1]=$time } }$taskdb.keys | %{
$taskdb.$_[2] = ($taskdb.$_[1] - $taskdb.$_[0]).totalmilliseconds
}
$taskdb.keys | %{ New-Object -TypeName PSObject -Property @{ Task =$_
Start = $taskdb.$_[0]
ElapsedTime = $taskdb.$_[2]
}
} | Sort-Object -Property start | Select-Object task, start, elapsedtime

0

Author Commented:
Thanks for the help, this answer was enough to set me on the right path.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.