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!
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.
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.
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.
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
.
.
Here is an XML with embedded style sheet. It will openas a converted HTML page.
http://www.designedsystemsonline.com/upload/demo/cdcatalog.xml
I see now what you’re talking about. When I get some time I’ll have to look into this further. Thanks.,
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
In this example I still have to create the xsl file, right?
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.
Definitely quirky. The XML entries are like this:
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!!
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.
Thanks. I was close to getting it working.
Oh. Sorry – I didn’t mean to spoil your fun. XPath can be a pain at time.
Not at all. I just needed to see what I was doing wrong. Thanks so much for the examples.
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.