Question about EnhancedHTML Module

This topic contains 17 replies, has 3 voices, and was last updated by Profile photo of touchstone_81 touchstone_81 3 years, 11 months ago.

  • Author
    Posts
  • #7964
    Profile photo of touchstone_81
    touchstone_81
    Participant

    Hello

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

    https://powershell.org/books/creating-html-reports-in-powershell/

    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

    ServerA

    ServerB

     

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

     

  • #7968
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #7969
    Profile photo of touchstone_81
    touchstone_81
    Participant

    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 = @()
    

     PROCESS {

    foreach ($computerin$computername) {

            $params = @{'As'='Table';

                                    'TableCssID'='tableDisk';

                                     'DivCssID'='divDisk';

                                      'EvenRowCssClass'='even';

                                        'OddRowCssClass'='odd';

                                        'MakeHiddenSection'=$false;

                                        'TableCssClass'='grid';

                                        'Properties'='Drive',

                                     @{n='Size(GB)';e={$_.Size}},

                                     @{n='Free(GB)';e={$_.Free};css={if ($_.FreePct -lt 10) { 'red' }}},

                                     @{n='Free(%)';e={$_.FreePct};css={if ($_.FreeePct -lt 10) { 'red' }}}}

            $html_dr  +=Get-InfoDisk-ComputerName$computer|

                       ConvertTo-EnhancedHTMLFragment@params|

                       Out-String

    write-host"stop here"

            } #end foreach

        }# end process

    End {

            $params= @{'CssStyleSheet'=$style;

                        'Title'="System Report for Servers";

                        'PreContent'="

    System Report for Servers

    ";

                        'CssIdsToMakeDataTables'=@('tableDisk');

                        'HTMLFragments'=@($html_dr)}

            ConvertTo-EnhancedHTML@params|

            Out-File-FilePath$filepath-Force

            } #end

     

             

  • #7975
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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 {
    
    param([string[]]$computername)
    
    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 "

    Disk Report

    " | 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.

  • #7978
    Profile photo of touchstone_81
    touchstone_81
    Participant

    sorry u had to see that ..  🙂  .

    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.
  • #7984
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #7985
    Profile photo of touchstone_81
    touchstone_81
    Participant

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

  • #8003
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #8005
    Profile photo of touchstone_81
    touchstone_81
    Participant

    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 :

    https://powershell.org/books/making-historical-and-trend-reports-in-powershell-free/

    this is going to be my next project 🙂

     

     

    Regards

    Kiran

  • #8069
    Profile photo of touchstone_81
    touchstone_81
    Participant

    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:

    [PRE]

    [/PRE]

    then replace this:

    [PRE]

    "$PreContent`n"

    [/PRE]

    with this:

    [PRE]

    $PreContent

    [/PRE]

    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.

  • #8076
    Profile photo of touchstone_81
    touchstone_81
    Participant

    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 :

    [PRE]

  • #8077
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #8078
    Profile photo of amolsp777
    amolsp777
    Participant

    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?

  • #8084
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #8085
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #8086
    Profile photo of touchstone_81
    touchstone_81
    Participant

    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 - http://validator.w3.org/  it did complain about a few minor issues but nothing major...i then tested it on jsfiddle.net 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...

  • #8087
    Profile photo of touchstone_81
    touchstone_81
    Participant

    just saw your post after i posted mine 🙂 ...thanks will try that...

  • #8128
    Profile photo of touchstone_81
    touchstone_81
    Participant

    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.

You must be logged in to reply to this topic.