Ouput to HTML

Hi guys,

I’m producing an Office365 health report, which i just want to output the html section, to a html document.I can style it later, but i’m struggling for some reason to work out the variable i need to grab to convert, i’ve tried using $events,$event and using $tables. I had it working before but i attacked this a while ago and have had a break from powershell / code in general, is anyone able to see what i need.

I did have it outputting to grid-view previously i remember, but again, I’ve lost that revision of the code…

Any help you guys could provide would be amazing!

There is some code previous to this section, but it’s just credential management and doesn’t contain anything relevant.

# gather events from the Service Communications API
$MySession = New-SCSession -Credential $Credential
$Events = Get-SCEvent -EventTypes Incident -PastDays 1 -SCSession $MySession |
    Select-Object Id, Status, StartTime,
    @{n='ServiceName'; e={$_.AffectedServiceHealthStatus.servicename}},

 if ($Events)
   $Tables = foreach ($Event in $Events)


Have you considered contacting Matt, the author of the module you’re using, to confirm which variable contains what you’re after?

Alternately, if I needed to figure this out on my own, I’d probably run the command manually and pipe it to Format-List *, so I could visually verify which property of the output I needed to work with.

Additionally, I suspect you have some HTML in there. The forums won’t render XML or HTML; you need to post your code as a Gist, and then paste the Gist URL into your message here. That’s a safety thing - any HTML or XML posted here is stripped to prevent certain cross-site security attacks.

Also, I’m not clear on whether you’re being GIVEN HTML, or whether you’re trying to CONSTRUCT HTML yourself. If it’s the latter, then I’d suggest reading our free ebook on HTML reporting. It’s a lot easier to use ConvertTo-HTML, or ConvertTo-EnhancedHTML, than to “roll your own” HTML conversion.

Hi Don,

Apologies, yes there is already some HTML in there, to format the look of the results, which was already kindly provided in the module. All i’ve done is stripped away the e-mail part of it and would just like to display it as a HTML output,

Here is the Gist if you did want to have a look:

I do definitely need to do some reading, i was just after the actual variable i needed to pipe out :slight_smile:

Many thanks

Having not used that module, I can’t tell you which variable - but piping them all to Format-List * is how I’d figure out which one I wanted. Good luck!

I would suggest just using Convertto-html -fragment which would be much easier. You can also add custom css to the header to format the table or anything else. Here is an example:

$Header = @"

table {
    width: 100%;
th {
tr:nth-child(even){ background:lightgrey; }                          


$HTML = Get-process | Select Handles, CPU, ProcessName | ConvertTo-Html -Fragment

ConvertTo-HTML -Head $Header -Body  $HTML | Out-File c:\temp\myreport.html