Process log file with powershell.

Posted on 2011-05-10
Last Modified: 2012-05-11
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

Question by:Blowfelt82
    LVL 13

    Accepted Solution

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


    Author Closing Comment

    Thanks for the help, this answer was enough to set me on the right path.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    A post on a forum I visit frequently mobilized me to create a script to remove a password (the one required to open a file) from any number of Word files. Because nobody would want to open a 100 files and manually save them... Of course, you have t…
    The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now