Posts
47
Comments
55
Trackbacks
0
Tweak master flash (or how you can tweak community scripts too)

Joey asked a cool question on my last post on out-html: what if you wanted to colorize the output of out-html so that some rows/values were colored differently based on a criteria?

I can think of a couple of different ways to handle this, and it certainly is a nice hack. But rather than building the solution, I'll post some hints and see if the community can pull some nice stuff together :). Here are some ideas: Since the goal is to color values in any given column/row a given color based on a certain criteria, why not parameterize this as a function of the input? In simpler terms, why not let the user pass in a "rule" on how out-html should color things?

To be even more specific: add a parameter (or more than one parameter) to the script that takes a color value, a criteria which when evaluated to true will apply that color, and finally a property to which the color/criteria should apply. Here's a usage pattern:

get-mailboxstatistics | out-html -property ItemCount -criteria { $prop -lt 100 } -color "Green"

Some further things to hack: how would you add support for more than one propertr and more than one criteria? Ok, so that's one approach. How about an approach which focuses on the input before it gets to out-html? Imagine a pre-processer to out-html:

get-mailboxstatistics | apply-colors | out-html

This function in the middle would output basically the same thing as get-mailboxstatistics except it would add the appropriate formatting to values that you care about. The downside of this approach might be that the function is tied to a particular input data set. But you could combine approaches #1 and #2 to come up with some common ground. So there are some ideas on how to do this.

As usual, I'm probably complicating things too much, so if you have a simpler solution... go for it and show us how its done :) If I get some more time to tweak I'll see if I can cook up a version of out-html that supports custom coloring. Till then, happy hacking!

posted on Thursday, May 11, 2006 10:05 PM Print
Comments
Gravatar
# 
Joey
5/26/2006 7:05 AM
  
Damn, I sure wish I was better at programming. My head starts to spin when I start trying to do this. I dont think I am cut out for programming. Its like being an artist, either you can do it or you cant.
Gravatar
# 
Joey
6/1/2006 8:06 AM
  
I finally got it to work, after lots of reading and help from www.scriptinganswers.com. I modified out-html to format with colors. Here is the portion of the code I modified:

I changed

foreach ( $p in $script:propsNames )
{
$holder.$type += '`t' + $i.$p + "`n"
}

$holder.$type += "`n"
$count++

to read like this


foreach ( $p in $script:propsNames )
{
if ($i.Size -gt 250000) {
$holder.$type += '`t' + $i.$p + "`n"
}
elseif ($i.Size -gt 200000) {
$holder.$type += '`t' + $i.$p + "`n"
}
else {
$holder.$type += '`t' + $i.$p + "`n"
}
}
$holder.$type += "`n"
$count++

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 2 and 1 and type the answer here:
News
A little slow these days as I'm busy working on exchangelabs.com. I will try and post tidbits when I get some time. Enjoy the older posts till then!