Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - Log In Out File Processing

Reply
 
Old 09-03-2008   #1 (permalink)
TimParker
Guest


 
 

Log In Out File Processing

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 laurastoneburner 09/03/2008 10:15:27.20 Login
machine2 reneehyde 09/03/2008 10:28:44.87 Login
machine3 reneehyde 09/03/2008 10:32:51.23 LogOut

My System SpecsSystem Spec
Old 09-03-2008   #2 (permalink)
TimParker
Guest


 
 

Re: Log In Out File Processing

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
Old 09-03-2008   #3 (permalink)
David Moravec
Guest


 
 

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
Old 09-04-2008   #4 (permalink)
TimParker
Guest


 
 

Re: Log In Out File Processing

David --

Thanks for the code. I will give that a shot. We took a bit of a
different approach and threw the data into a couple hashtables and
have it almost working well. But I am now to almost the end of the
"current" requirements for this.

I have a hash table that returns If I type the folliowing:

PSH> $users[$key]

Name
Value
----
-----
WKSTN0033 Login

so If then type the following I would expect to get true back but it
returns false.

$users[$key].ContainsValue("Login")

Any ideas why? There are no spaces around the text. We did have some
spaces in the beginning due to the way that I wrote the original batch
file, but I cleaned all that up.

TIA.

Tim



On Sep 3, 2:24*pm, David Moravec <David
Mora...@xxxxxx> wrote:
Quote:

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

> > *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.
>
Quote:

> > *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
>
Quote:

> > 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).
>
Quote:

> > Thoughts on the best way to sort through this and come up with the end
> > result.
>
Quote:

> > TIA.
>
Quote:

> > Tim- Hide quoted text -
>
> - Show quoted text -
My System SpecsSystem Spec
Old 09-04-2008   #5 (permalink)
Flowering Weeds
Guest


 
 

Re: Log In Out File Processing

Quote:

> 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.
Perhaps see the post
Log Parser - The Report

Have some fun - Log Parser it!


My System SpecsSystem Spec
Old 09-04-2008   #6 (permalink)
TimParker
Guest


 
 

Re: Log In Out File Processing

Well, thanks, but that doesn't answer my question, anyone? See
previous reply for the question. Thanks.



On Sep 4, 3:56*pm, "Flowering Weeds" <floweringnoweed...@xxxxxx>
wrote:
Quote:
Quote:

> > 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.
>
> Perhaps see the post
> Log Parser - The Report
>
> Have some fun - Log Parser it!
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Processing XML PowerShell
XML processing my web.config file in PowerShell PowerShell
More text processing. PowerShell
Clear-Content Cmdlet and Processing Lines in Text File PowerShell
Skeleton for file processing scripts PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46