r/PowerShell • • Aug 04 '19

Script Sharing Working with HTML in PowerShell just got better

Here's a short article on how you can use new features of PSWriteHTML, Emailimo or Dashimo

https://evotec.xyz/working-with-html-in-powershell-just-got-better/

I've added a lot of nice features for tables and reworked lots of code. It's possible to achieve much more now when creating reports, dashboards or sending emails. Statusimo changed its look a bit, but not so much. Enjoy and if something doesn't work let me know :-) New feature requests are also welcome.

If you work with HTML - creating reports, creating emails - this one is for you. Below screenshots were created with almost 0 effort.

127 Upvotes

17 comments sorted by

3

u/[deleted] Aug 04 '19

Always good stuff. Thought about using bootstrap for your UI instead of raw HTML generation?

4

u/MadBoyEvo Aug 04 '19

Well, I am not sure what are the differences really. I'm using Flexbox for layout which I read is not really something that plays well with bootstrap. Isn't bootstrap still the same stuff? I will still have to generate HTML just in a different form?

3

u/1RedOne Aug 04 '19

Bootstrap 4 has native flexbox support. It didn't work super well in Bootstrap 3.3.6 but you could use it.

If you were to use Bootstrap for the email you could get some nice resizing based on their device, but it's pretty big payload to include in an email and I don't think you can link a Css file in an email. (I might be wrong)

2

u/MadBoyEvo Aug 04 '19

I will be exploring bootstrap to see if it can be mixed together. Maybe. Emails are tricky. Outlook on desktop behaves differently then gmail or other clients. Thanks!

2

u/nkasco Aug 04 '19

2 questions:

  1. Does this support auto-update naively or do I need to come up with something?

  2. Does it support being hosted internally?

3

u/MadBoyEvo Aug 04 '19
  1. When there is new version simply Update-module ... if thats what you are asking

  2. This module generates static html file. This means the data is there, inline. You can take that html put it on usb stick and it will work. You can host it on iis, you can host it on linux. Its single html file, nothing else. You are responsible for security of it.

3

u/nkasco Aug 04 '19

Looking for more features similar to Universal Dashboard

2

u/MadBoyEvo Aug 06 '19

I am not implementing "hosting" for security reasons. You can, however, open up IIS or Apache and have your HTML hosted there. It should be pretty easy. One of the users on PowerShell Polish Group had PSWriteHTML running as CGI where data was generated on the fly when someone accessed the webpage.

In case of normal hosting you would:

  1. Setup IIS website

  2. Point it to Index.html

  3. Tell PSWriteHTML to generate index.html

  4. Setup task scheduler to regenerate that index.html

That's it. You could probably hook it up to Polaris.

Universal Dashboard is an ultimately different beast, and I have no intention to try and deliver similar functionality.

PS. Maybe you mean auto-refresh of content in PSWriteHTML? If so, then yes New-HTML has an option -autorefresh <int> which will autorefresh Html every X seconds. This means the browser will be refreshing HTML for a user. However since the HTML content is static, nothing will change unless you will have the task scheduler in the background generating new content for you.

2

u/chump_nz Aug 06 '19

This is really smooth, thanks MadBoyEvo! It's helping me make something ugly a lot more elegant and shareable. I'm having some issues (user error?) figuring out how to get html anchors to display as hyperlinks when using new-htmltable on an array. It seems to always output as a string, whether I make the array field general html or stuff format. Any advice?

3

u/MadBoyEvo Aug 06 '19

There's no direct link conversion built-in because it's hard for me to know whether you want the link to be active or not active. By default, New-HTMLTable doesn't do tags conversions either.

Here's how you would do it: https://github.com/EvotecIT/PSWriteHTML/issues/30

You need to:

  1. Use -InvokeHTMLTags (otherwise HTML tags are visible as is)

  2. Use HTML within the object you're passing.

You can use any HTML you want in OBJECT and after you use -InvokeHTMLTags it will convert those to their HTML representation.

Something like this will do:

$customobject = [pscustomobject]@{user = 'user1'
    name                               = 'thom'
    link                               = 'https://powershellposse.com'
    activeLink                         = '<a href="https://powershellposse.com">You can use here text or again link</a>'
}
New-HTML -titletext 'test' -useCsslinks:$true -useJavascriptlinks:$true -filepath $PSScriptRoot\Teo.html -ShowHTML {
    New-HTMLTab -tabname 'summary' {
        New-HTMLContent -HeaderText 'summary' {
            New-HTMLTable -DataTable $customobject -InvokeHTMLTags -HideFooter
            New-HTMLTable -DataTable $customobject -HideFooter
        }
    }
}

1

u/chump_nz Aug 06 '19

I was so close! Dropped in the -InvokeHTMLTags and it was perfect. Thanks for the help, and great project.

1

u/HamQuestionMark Aug 04 '19

Awesome! Going to give these a try instead of ReportHTML in my next script

1

u/MadBoyEvo Aug 04 '19

Hopefully, you will see some improvements over ReportHTML. It's a fork, but right now I think it's a totally different product.

3

u/tschertel Aug 04 '19

Really nice. Thanks for this.

1

u/This_Bitch_Overhere Aug 04 '19

I am just now getting started with PS, but I’ve found it to be or it will be very useful in my daily/weekly/monthly tasks. While I don’t understand the words that are coming out of your mouth, I can’t wait to look at this on my machine and figure it out. It looks awesome. Thank you!

3

u/MadBoyEvo Aug 04 '19

If you're new to the whole concept please start with earlier blog posts before jumping in on this one. While copy/pasting some stuff should work (assuming you will get past Install-Module part) I've skipped a lot of basics here (hence why some things may sound complicated).

2

u/This_Bitch_Overhere Aug 04 '19

Oh, absolutely! I am not going to jump into deploying this without first knowing the basic concepts. Thank you!