Solved

# Process log file with powershell.

Posted on 2011-05-10
649 Views
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

0
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.$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 Closing Comment

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

## Featured Post

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 (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". 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…