Question about EnhancedHTML Module


first off- let me say thanks for this wonderful module.

I love the pagination, column sorting and also the filtering options, they are great…

The script currently produces a different html file for each computer that i run it against. What i would like to do is to get the information for all computers in one html file and in a single table. I do not necessarily want OS or other general info in the same file. I genereally keep my reports specific to one category …disk,network etc

For eg . lets say i am querying for disk information for serversA and serverB. Â I would like to see the report in the following form.

Computername   Disk   freespace    used    total percent




Would appreciate if Don or someone can help me out with this.


So, the EnhancedHTML module lets you do that. The demo script is what uses the module to produce one page per computer.

All you have to do is create a fragment per computer, and then bundle those together into a completed page. So instead of a section for disk, a section for processes, etc., you do a “section” per computer. Same basic pattern as the demo script.

What you’re wanting is really simpler. You just need to produce a function that outputs one object per disk per computer. So, feed the function a bunch of computer names, and it queries them. For each disk,it outputs an object with Computername, Disk, Freespace, etc. Those objects get piped to make a single, one-section HTML report, since all you’re after is a single table. You only need to do multiple fragments if you want multiple tables in the report, like the demo does.

thanks for the quick reply.

i tried this below but dosent seem to create a table. besides i get the feeling even if it works it is going to create multiple headers within the table.

$html_dr = @()
<p class="p1"><span class="s1">Â </span>PROCESS<span class="s2"> {</span></p>
<p class="p2"></p>
<p class="p3"><span class="s3">foreach</span><span class="s2"> (</span>$computer<span class="s3">in</span>$computername<span class="s2">) {</span></p>
<p class="p4"></p>
<p class="p2">Â  Â  Â  Â Â <span class="s6">$params</span> <span class="s4">=</span> @{<span class="s8">'As'</span><span class="s4">=</span><span class="s8">'Table'</span>;</p>
<p class="p4">Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  <span class="s8">'TableCssID'</span><span class="s4">=</span><span class="s8">'tableDisk'</span>;</p>
<p class="p4">Â Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  <span class="s8">'DivCssID'</span><span class="s4">=</span><span class="s8">'divDisk'</span>;</p>
<p class="p4">Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  <span class="s8">'EvenRowCssClass'</span><span class="s4">=</span><span class="s8">'even'</span>;</p>
<p class="p4">Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  <span class="s8">'OddRowCssClass'</span><span class="s4">=</span><span class="s8">'odd'</span>;</p>
<p class="p4">Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  <span class="s8">'MakeHiddenSection'</span><span class="s4">=</span><span class="s6">$false</span>;</p>
<p class="p4">Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  <span class="s8">'TableCssClass'</span><span class="s4">=</span><span class="s8">'grid'</span>;</p>
<p class="p4">Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  <span class="s8">'Properties'</span><span class="s4">=</span><span class="s8">'Drive'</span><span class="s4">,</span></p>
<p class="p4">Â Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  @{n<span class="s4">=</span><span class="s8">'Size(GB)'</span>;e<span class="s4">=</span>{<span class="s6">$_</span><span class="s4">.</span>Size}}<span class="s4">,</span></p>
<p class="p4">Â Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  @{n<span class="s4">=</span><span class="s8">'Free(GB)'</span>;e<span class="s4">=</span>{<span class="s6">$_</span><span class="s4">.</span>Free};css<span class="s4">=</span>{<span class="s3">if</span> (<span class="s6">$_</span><span class="s4">.</span>FreePct <span class="s4">-lt</span>Â 1<span class="s9">0</span>) { <span class="s8">'red'</span> }}}<span class="s4">,</span></p>
<p class="p4">Â Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  @{n<span class="s4">=</span><span class="s8">'Free(%)'</span>;e<span class="s4">=</span>{<span class="s6">$_</span><span class="s4">.</span>FreePct};css<span class="s4">=</span>{<span class="s3">if</span> (<span class="s6">$_</span><span class="s4">.</span>FreeePct <span class="s4">-lt</span>Â 1<span class="s9">0</span>) { <span class="s8">'red'</span> }}}}</p>
<p class="p3"><span class="s2">Â  Â  Â  Â  </span>$html_dr<span class="s2">Â  </span><span class="s4">+=</span><span class="s5">Get-InfoDisk</span><span class="s10">-ComputerName</span>$computer<span class="s4">|</span></p>
<p class="p7"><span class="s2">Â Â  Â  Â  Â  Â  Â  Â  Â  Â  </span>ConvertTo-EnhancedHTMLFragment<span class="s6">@params</span><span class="s4">|</span></p>
<p class="p4">Â Â  Â  Â  Â  Â  Â  Â  Â  Â  <span class="s5">Out-String</span></p>
<p class="p5"><span class="s5">write-host</span>"stop here"</p>
<p class="p2"></p>
<p class="p8"><span class="s2">Â  Â  Â  Â  } </span>#end foreach</p>
<p class="p2"></p>
<p class="p8"><span class="s2">Â  Â  }</span># end process</p>
<p class="p1">End<span class="s2"> {</span></p>
<p class="p2"></p>
<p class="p5"><span class="s2">Â  Â  Â  Â  </span><span class="s6">$params</span><span class="s4">=</span><span class="s2"> @{</span>'CssStyleSheet'<span class="s4">=</span><span class="s6">$style</span><span class="s2">;</span></p>
<p class="p5"><span class="s2">Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span>'Title'<span class="s4">=</span>"System Report for Servers"<span class="s2">;</span></p>
<p class="p5"><span class="s2">Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span>'PreContent'<span class="s4">=</span>"<h1>System Report for Servers</h1>"<span class="s2">;</span></p>
<p class="p5"><span class="s2">Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  </span>'CssIdsToMakeDataTables'<span class="s4">=</span><span class="s2">@(</span>'tableDisk'<span class="s2">);</span></p>
<p class="p4">Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  <span class="s8">'HTMLFragments'</span><span class="s4">=</span>@(<span class="s6">$html_dr</span>)}</p>
<p class="p7"><span class="s2">Â  Â  Â  Â  </span>ConvertTo-EnhancedHTML<span class="s6">@params</span><span class="s4">|</span></p>
<p class="p6"><span class="s2">Â  Â  Â  Â  </span><span class="s5">Out-File</span>-FilePath<span class="s6">$filepath</span>-Force</p>
<p class="p4">Â  Â  Â  Â  } #end</p>
<p class="p2">Â  Â  Â  Â  Â 

Um, yeah, pasting HTML into a Web site doesn’t work well :).

So, I’m afraid I don’t have time today to write the whole thing for you. But I think you’re on the wrong general approach. You need to start by getting the output you want in the console. The HTML comes later.

function Get-DiskInfo {


foreach ($computer in $computername) {

$disks = get-wmiobject win32_logicaldisk -filter "drivetype=3" -computer $computer

foreach ($disk in $disks) {

$p = @{'computername'=$computer;'drive'=$disk.deviceid;'size'=$disk.size;'free'=$disk.freespace}

New-Object PSObject -Prop $p




Something like that. If you then run:

Get-DiskInfo -comp SERVER1,SERVER2,SERVER3 | ConvertTo-HTML -Pre "<h1>Disk Report</h1>" | out-file whatever.html

You should get a non-enhanced, single-table HTML report. You don’t need HTML fragments in this case. Converting this into an EnhancedHTML report is fairly straightforward… and i can help with that, but make sure you’re happy with the basic layout of the non-enhanced version first. That way I understand what you’re after, and you know that you’re producing the proper input for the HTML report.

sorry u had to see that … Â :slight_smile: Â .

I thought I enlosed the code in

 [\pre] or maybe i put curly brackets or something …anyway

thanks for the tip…Let me work on the above and post my progress.

You can attach files, and I suggest you do that for long chunks of code or HTML files. Please don’t paste text from other applications - your browser is interpreting what’s on your clipboard as HTML, and it’s rendering as unreadable. If you need to copy/paste from an app, paste into Notepad first to strip off the formatting in the clipboard.

i cant  seem to post plain text…i am putting the whole thing into a text file .

So, you’ve asked a couple of questions here.

First, EnhancedHTML does require a fragment. You would produce ONE, because you want one table in the output. That one fragment would contain ALL of your data. You’d send that ONE fragment into the final HTML file.

Second, you asked about a template. Nothing in the module I wrote does templates.

Without running it, your code looks basically correct. You’re producing one fragment, and making a page out of it. That’s exactly the intent. If it’s producing what you want, you’ve got it right.

Awesome thanks for the explanation…

About the templates - i did not mean that literally…I understand that as long as i can get my script to output to a grid i can use the enhanced html module to produce  great looking reports… so basically i can produce reports that are consistent.

My Tip for the community: Â Â Â output your data to a csv file. Extract the output using import-csv and pipe that to create an html fragment which can then be used to create a table. I am not going to paste this example for fear of messing up the post…but i am sure you get the idea.

As a side note, i would like to thank you Don for enabling me to learn powershell. My first lessons in powershell were from the cbt nuggets that you  made which i think is still the best training course for anybody that wants to start learning powershell. Your teaching style is very effective and I wish ppl who teach programming languages take a leaf out of your book. There are a lot of ppl with great amounts of knowledge but not all of them are good tutors for teaching is an art that is mastered only by a few.

For a long time i have wanted to put all the data i gather from various sources into a database for trending and with this ebook that seems to be a definite possibility :

this is going to be my next project :slight_smile:





Some Feedback about the Module:

after having created a few reports some ppl came back to me and said they couldnt view the tables by clicking on them in other words the toggle function of the table didnt work. I did some research and found that the script produces an html file that works perfectly with IE but does not work with the latest versions of : Chrome,Firefox or Safari.

I Â tried a few things to get it to work on other browsers but only in vain. I dont know much about html but the only way i have found to make this work is by tinkering with the original code like so:

add the following javascript function:


<script type=“text/javascript”>

function toggle_visibility(id) {

var e = document.getElementById(id);

if( == ‘block’) = ‘none’;

else = ‘block’;




then replace this:


“<span class=&quot;sectionheader” onclick=&quot;$(’#$DivCssId’).toggle(500);&quot;&gt;$PreContent&lt;/span&gt;n"


with this:


<div  class=“sectionheader” onclick=“toggle_visibility(’$DivCssId’);”>$PreContent</div>


Also the above works only when the values for both $DivCSSid and $tableCSSid  are the same…

This may not be the most efficient way of doing it and I am sure there would be other ways. If someone knows a better approach i would really appreciate if some examples can be posted.

cant seem to edit my own post…dont see the edit button…anyway update tot he above: enbaling the toggle using the custom function seemed to remove the search and pagination features so if you can live without the toggle function then just change the line from :


<div id=“divid” style=“display:none;”>




<div id=“divid” style=“display:show;”>



The edit button is in the header bar above the message text.

The module doesn’t do any of the fancy stuff itself; it simply includes jQuery, which is cross-browser compatible. You’ll need to check your system configuration; I’ve never actually used the module with IE - I only use it with FF, and on the Mac, Safari. Never had an issue with it. But the toggling is just a jQuery call. I can’t change the way that works without writing jQuery, which I’m not up to :).

If you don’t want the toggling for a section, then you should simply not enable it. When you use ConvertTo-EnhancedHTML, you pass a list of CSS IDs to make toggles - just omit any tables that you don’t want toggled and it won’t add the Javascript to those tables, and they won’t have display:none added to their local style.

Really a good code…

But I am looking simple code where ActivX popup not required (Jquery not required) to collapse the headers.

I am not sure it possible or not, could you please assist here?

There’s no ActiveX involved. It’s Javascript.

And unfortunately I’m not your guy for Javascript. The reason I used jQuery in the module is because it does the work for me. If you want to do something else, I’m afraid I won’t be of any help to you.

And, as I said, if you just want to TURN OFF the collapsing, you can do that easily. As described in the ebook, just don’t use the -MakeHiddenSection parameter when you produce HTML fragments. There are two examples in the “New EnhancedHTML Module Demo.ps1” script that set -MakeHiddenSection to $False. When you do that, the section isn’t hidden and isn’t able to be toggled.

I can’t help you add toggling without the use of JQuery, but if you just want to eliminate the toggle, that is supported in the module already.

yeah it is weird. when in office i mainly use IE 8 and it worked fine, I only came to know about the browser issue when someone complained to me…so i fired up chrome and it didnt work there , came home tried it on my mac in safari… same thing…so not sure what is happening maybe it is a version issue…i validated the html on -  it did complain about a few minor issues but nothing major…i then tested it on and couldn’t get it to work…

anyways not a big deal, like i said i have disabled the toggle which as you mentioned is a simple jquery call and retained just the pagination and filter functions which are working for me…

It would be nice to hear the experience of others who have used it or will use it once they see this thread…

just saw your post after i posted mine :slight_smile: …thanks will try that…

please disregard my comments about changing any of the code in the module. Â Everything works well if you use :


out-file with the -encoding parameter  and specify ascii as the value :).

tested on a windows 7 machine with powershell V3.

i was inspired to create a few style sheets; some work on all browsers while others not. So for those of you who would like to customise the look do check how the style behaves,  both in IE as well as FF or chrome.