View Single Post
Old 09-03-2008   #3 (permalink)
David Moravec


 
 

Re: Log In Out File Processing

Hi,
You can use something similar to this:

$file = Get-Content ./log.csv

$h = @{}
$htmlFile = "output.html"
$htmlBegin = "<html><head></head><body><table>"
$htmlMid = ""
$htmlEnd = "</table><br>By PowerShell </body>"

foreach ($line in $file) {
$hk = $line.split(";")[1]
$hv = $line.split(";")[4]
$h[$hk] = $hv
}

$h.get_Keys() |% {
$htmlMid = $htmlMid + "<tr>"
if ($h.Get_Item($_) -eq "Login") {
$htmlMid = $htmlMid + "<td bgcolor=`"green`">$_</td>"
$htmlMid = $htmlMid + "<td bgcolor=`"green`">" + $h.Get_Item($_) + "</td>"
}
else {
$htmlMid = $htmlMid + "<td bgcolor=`"red`">$_</td>"
$htmlMid = $htmlMid + "<td bgcolor=`"red`">" + $h.Get_Item($_) + "</td>"
}
$htmlMid = $htmlMid + "</tr>"
}

Set-Content $htmlBegin$htmlMid$htmlEnd -Path $htmlFile

Enjoy it,
David


"TimParker" wrote:
Quote:

> Sorry, hit the wrong key.....
>
> I have a new project that I am working on, my boss decided to morph a
> previous project and add something new to it now. I have a file that
> I
> have is created through login and logout scripts. The following is
> the
> layout for the CSV file.
>
> machine1 user1 09/03/2008 10:15:27.20 Login
> machine2 user2 09/03/2008 10:28:44.87 Login
> machine3 user3 09/03/2008 10:32:51.23 LogOut
>
> I need to be able to loop through this data and create a web page that
> say changes the color of their name to either red or green for in the
> office or out. I am pulling the data from the file based on the
> current date. So I can have multiple logins and multiple machines even
> per user. My boss is thinking that I need to look at matches, same
> machine, user and ignore those and then that will leave potentially a
> login (still in the office).
>
> Thoughts on the best way to sort through this and come up with the end
> result.
>
> TIA.
>
> Tim
>
>
>
My System SpecsSystem Spec