Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Creating Styling HTML Reports with PowerShell

Posted on August 26, 2013

Last month I did an updated version of my presentation on creating styling HTML reports in Windows PowerShell. This presentation was for the PowerShell virtual chapter of SQL PASS. As such, I came up with some SQL related demonstrations and fine tuned some demos from earlier presentations.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

You can download a zip file with a PDF of my slides as well as my demo scripts.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

16 thoughts on “Creating Styling HTML Reports with PowerShell”

  1. jvierra says:
    August 30, 2013 at 11:18 am

    Jeff – excellent presentation. I am glad to see there is interest in leveraging PowerShell and HTML/CSS. The XML access is also valuable for building reports.

    Have you considered XML data islands, XSL/XSLT for customizing reports.

    1. Jeffery Hicks says:
      August 30, 2013 at 11:22 am

      That’s a little bit above my pay grade. But if you want to point me to some docs and/or examples I’m happy to take a look.

      1. jvierra says:
        August 30, 2013 at 1:02 pm

        No need for that. We just use PowerShell to dump XML then apply a stylesheet.

        I prefer self generated xml using the xml type and just add a reference to a styleshell (xslt). When we open the xml it gets styled.

        I have some examples in VBScript that I will try to convert to PowerShell.

        See: http://www.w3schools.com/xsl/

        Try the example and note how easy it is to keep data separated from presentation.

        Here is an example of linking a stylesheet to an XML document: Note line 2. That is all. We add it using createProcessingInstruction / appendChild. With this we mcan very easily just generate data and have it display in HTML or do almost anything we want with it. All browsers work with this.

        Empire Burlesque
        Bob Dylan
        USA
        Columbia
        10.90
        1985

        .
        .

      2. jvierra says:
        August 30, 2013 at 1:20 pm

        Here is an XML with embedded style sheet. It will openas a converted HTML page.

        http://www.designedsystemsonline.com/upload/demo/cdcatalog.xml

  2. Pingback: Why you can’t enumerate invocable methods within Powershell | mbrownnyc
  3. Jeffery Hicks says:
    August 30, 2013 at 2:22 pm

    I see now what you’re talking about. When I get some time I’ll have to look into this further. Thanks.,

    1. jvierra says:
      August 30, 2013 at 4:04 pm

      Here is the PowerShell part of this for a basic custom table. Later I will up load the full converted project as a demo. It is relly pretty cool and it allows us to reformat the same dta many times. We can slo easily embed code into the XSLT and have very dynamic reports withut having to do any more than just generate an object collection. Style sheets canbe linked and they can be smart.

      PosH Code —>

      #create an xml object from a selection of properties of directory listing
      [xml]$xml=dir c:\scripts\*.ps1 |
      select mode,LastWriteTIme,Length,Name |
      ConvertTo-Xml

      # add a processing instruction containing to refernce to the XSLT style sheet we want to use.
      $pi=$xml.CreateProcessingInstruction(‘xml-stylesheet’, ‘type=”text/xsl” href=”scripts.xsl”‘)
      [void]$xml.InsertBefore($pi,$xml.DocumentElement)

      # save the XML and run it.
      $xml.Save(‘c:\scripts\scripts.xml’)
      c:\scripts\scripts.xml

      1. Jeffery Hicks says:
        August 30, 2013 at 4:31 pm

        In this example I still have to create the xsl file, right?

      2. jvierra says:
        August 30, 2013 at 5:26 pm

        You can use a stock XSL but the column names may need to be synced in the extract.

        The XSLTs are not so bad once you get used to how to get around the XSL quirks.

      3. Jeffery Hicks says:
        August 30, 2013 at 5:33 pm

        Definitely quirky. The XML entries are like this:

        -a— 7/31/2013 4:47:28 PM 3795 13ScriptBlocks-v2.ps1

        So I’m trying to get the selection to use the Name attribute of each property which I hope will then get the value. Oh, and curse you and your shiny ball!!

  4. jvierra says:
    August 30, 2013 at 7:12 pm

    Here is a copy of a style sheet that is simple and works for this:

    http://www.designedsystemsonline.com/upload/demo/DEMOXSL/scripts.xsl

    Here is the companion XML as generated:

    http://www.designedsystemsonline.com/upload/demo/DEMOXSL/scripts.xml

    That one will display as HTML but source is XML and can be saved.

    Here is the CSS style sheet.

    http://www.designedsystemsonline.com/upload/demo/DEMOXSL/scripts.css

    I have another short routine which actually generates an HTML file which is good for making archived reports or generating email bodies. It uses the XmlXsl compiler in dotNet.

    1. Jeffery Hicks says:
      August 30, 2013 at 9:34 pm

      Thanks. I was close to getting it working.

      1. jvierra says:
        August 30, 2013 at 10:10 pm

        Oh. Sorry – I didn’t mean to spoil your fun. XPath can be a pain at time.

      2. Jeffery Hicks says:
        August 30, 2013 at 10:13 pm

        Not at all. I just needed to see what I was doing wrong. Thanks so much for the examples.

      3. jvierra says:
        August 30, 2013 at 10:23 pm

        Just kidding. I got stuck on the same thing because I couldn’t remember how to unpack attributes in a loop. Like an idiot I tried to look for examples in the web but ll of the examples were totally wrong. Then it dawned on me what I was forgetting.

        The for-each loops and evaluates all select-value statements. Set the value to @Name=’somename’ and it returns the text of the attribute with that ‘Name’. So enumerating ‘Object’ and match on Property whose Name Is the “name” we are lloking to grab the property value for.

        Now that is confusing and I never can remember it after not using it for a while.

        I love things designed by a committee.

        Anyway. XSLT is extremely useful for generating HTML.

  5. Pingback: Creating Styling HTML Reports with PowerShell | bbnetman.com

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d