Monday, April 23, 2018

Out-Internet_explorer

Output to a web browser? But why?
I was fishing around in the PowerShell Studio Snippets and a ran across one Snippet:called Trace.

I wanted to use this snippet to upgrade the output of my troubleshooting tool, ServerPulse. An update of a script that I originally wrote to give text output. With this connection to Internet Explorer, I could create something that was a bit easier on the eyes and stop the junior engineers from puckering when they looked at it. ServerPulse was a text-based self-updating dashboard which I thought was rather functional. however, I could see a bit of aesthetics to making it browser output.  I think there is a lot of possibilities with formatting the output as HTML and then it could be delivered by file, email,  or to a web browser.

This update would give me time to rethink what and how I was gathering the data. Keeping the live data refreshing feature of the troubleshooting tool would be important.

I did some tweaking on the base snippet.

I played with this on my workstation, and when I tried it on a server I got some weird errors.

Problem is this requires a certain DLL to function - "Microsoft.mshtml.dll"
It may not be loaded on a server or workstation in some conditions. I have read that MS office installs it.  Here is a more detailed article in how to add it if you get the error "Property 'innerhtml' cannot be found on this object; make sure it exists and is settable."
Check out - http://www.dlldownloader.com/microsoft-mshtml-dll/ with a detailed explanation of the problem.

After fixing that, I was able to use it any computer that had the dll, I read that the Microsoft Office suite added this dll, which was the cause of the initial confusion with the server version, Which had no reason for it to have MS office installed.

So I created the following function from the snippet to post things to the Web page. You can repeatedly call this function to update information if you want to refresh or expand on the output. The flexibility of the Web browser interface is almost without limit.

But... You have to feed it HTML.
Besides hello world, I thought a basic clock would be in order.
Clock code to HTML A little adjustment to the function like so:
And when feed the output the clock code to the function it pops up a window like this:
" Out-IE ($report) "

IE WINDOW:

Hard to look at and kind of cryptic. But re-using some old MS script example, I can append a block of formatting to make it a little prettier.

* NOTE: If your playing with this on the Shell prompt, Make sure you get the $IE = ""In there someplace between sessions or you won't get a new window...  which was confusing at first for me.
And this is a feature for being able to update the data.

The Refined  IE output portion now looks like:




Now some more example of use.

Building on that code I added another table and gleaned some additional info from the local system. Then you can loop the code to keep it updating the output on IE. The next step was to add some more useful info: And I added some more useful info. An example finished script:

Output of this looks like:


And this version updates the info on the screen, you can see the values change, and the clock ticking.

No comments:

Post a Comment