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
   PackageStart,TASK1,13/04/2011 09:00:04
           PackageStart,TASK2,13/04/2011 09:00:04
    
           PackageEnd,TASK2,13/04/2011 09:00:04
   PackageEnd,TASK1,13/04/2011 09:00:04
   PackageStart,TASK3,13/04/2011 09:00:04
    
   PackageEnd,TASK3,13/04/2011 09:00:04
PackageEnd,ETLJOB,13/04/2011 09:00:04

Open in new window

Blowfelt82Asked:
Who is Participating?
 
soostibiConnect With a Mentor 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

Open in new window

0
 
Blowfelt82Author 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.

All Courses

From novice to tech pro — start learning today.