All posts by Jeffery Hicks

Converting Text to HTML Revised

A few years ago I published a PowerShell function to convert text files into HTML listings. I thought it would be handy to convert scripts to HTML documents with line numbering and some formatting. Turns out someone actually used it! He had some questions about the function which led me to revisit it and realize there were some improvements to be made.

Part of the challenge with this project is that the function takes an existing text file and creates a much larger text file. On one hand this is to be expected because we are adding HTML to it.  But I wanted to find ways to keep the size down.

After some HTML style tweaking, I found a better way to preserve the  formatting without dramatically increasing the file size. I also added an option so that you can specify an alternate CSS file. If you don’t use one, then the function will insert a default style into the head section. I also gave you the option to specify your own document title.

The revised script, which includes defining an alias, is now a gist on GitHub.

The function behaves much like ConvertTo-HTML in that it doesn’t create an actual file. You still need to pipe the output to Out-File.  And you should use Out-File instead of the console redirection character (>) as that created a much larger version of the file.

Here’s an example of a converted file using the default style sheet.

convertto-htmllisting2

If you want to create your own style sheet, be sure to use the setting white-space:pre; as this should retain document formatting. At least the best it can.

I hope you’ll find this helpful. Enjoy.

Formal Remote ISE Connections

I have updated my PowerShell tools that make it easier to open up a remote tab in the PowerShell ISE.  The standard approach is limited and doesn’t allow for things like using SSL or different ports.  I have had the ISERemoteTab project up on GitHub for awhile.

I recently added a WPF-based form to make it easier to make remote connections.

remoteIsetabYou can enter in a single computer or multiple computers.  Although, if you use multiple computers, the same settings will apply to all of them. But once I hit connect, I get new remote tabs.

remotetabsIn this example I am using the remote profile script feature to run a set of PowerShell commands after making the remote connection.

In my ISE profile script I added these lines to create a new Add-On shortcut.

All of this has also been published to the PowerShell Gallery. If you are running PowerShell 5 you can use Install-Module to install  ISERemoteTab.

I hope you’ll try it out and let me know what you think. If you run into bugs or have feature requests, please post them on the Github project site.

PowerShell Toolmaking Dos and Don’ts

During the last Microsoft MVP Summit, Channel 9 invited MVPs into their studios to record short presentations on anything they wanted. This was too good a deal to pass on, so my friend Greg Shields and I jumped into the studio to talk about PowerShell Toolmaking. To be more accurate, Greg, who knows a little PowerShell and is probably like many of you,  “interviewed” me about some toolmaking best practices.  The video is now available on Channel 9. Or you can watch it here.

Enjoy!