+menu-


Output a sortable HTML table

A while back I posted a script that would take whatever input it got, into a sortable HTML table in a file.

Last night my family was here, and they wanted to see the Eurovision song contest thing, so I had some time to rewrite the script into a PowerShell V2 Advanced function, that supports pipeline input.

There are some examples in the code on how to use the function

I do not know what has happened to code highlighter, but it has suddenly decided to mess up the code, so it is not working on the site, so here is a link to the file.

Out-HTMLTable

Example of output:

Out-HTMLTable example

download | new post

4 Responses to Output a sortable HTML table

  1. Very cool, I’ll have to check this out. One minor comment though: I think it’s confusing to use a verb-noun naming convention for the module itself. Modules are meant to be containers for a function, usually more than one. They are an abstraction layer one level up, if you will. Due to this, I think a best practice here would be for you to rename your module to something generic. That would allow you to add other functions, aliases, formatting ps1xml, binary snapins, etc, etc, etc to the same module.

    Or, if you wish it to simply standalone, then the way I would do that is to abolish mention of a module entirely and just make it a ps1 without even a wrapper function. In my experience, it’s hardly worth the time to explain to someone how to dot-source a file containing a function for just one thing.

  2. I agree with Hal about this not being a module.

    That aside, I can’t get it to work, even with the included examples. I suspect there was a problem pasting the code into the post. For example, the opening block-comment tag has an extra space (that one is easy). A bigger problem is in line 73 (in the “end” block). In the third .replace() call, the first argument is “”. You can’t pass an empty string as the first argument to replace. The same thing goes for the last replace in that statement.

  3. Hal & Mike

    Mike I am sorry that somehow the Codehighlighter screwed up the formatting, will see if there is an error in the highlighter brush, I put a link to the file, and I just tested it, it works.

    You are both completely right about the module/function observations, and I will change that… I was considering creating a report module, with different types of Report outputs, but a friend needed the htmltable functionality, so I might have posted a little prematurely (there are missing some params like report file name etc, hopefully I will have some time tonight to fix it), when I get those things worked out, I plan to post it on PoshCode as well.

    I ham trying to get a hold of LucD to see if I can include his Out-XLS into what is supposed to become a module :)

    Please let me know if you have trouble getting this to work, I have tested it with both pipeline input, and using variables and it seems to work for me.

  4. Not a problem. I can understand how the syntax hightlighter could have issues with html tags in strings. It’s working better now.