Converting PowerShell Scripts to HTML for Documentation

February 21, 2017 at 2:11 pm Leave a comment

There are times when you want to publish a PowerShell script for documentation in a format where having it as HTML is the best option, such as in a blog posting.

I have used a couple of approaches for this.

One is to use an addin for PowerShell-ISE from Gary Lapointe which can be accessed from ISE’s Add-on’s menu and selecting the Add-ons Tools Website option or http://blog.falchionconsulting.com/index.php/2012/10/windows-powershell-v3-ise-copy-as-html-add-on/.

The other is to use PowerShell Studio from Sapien  https://www.sapien.com/software/powershell_studio.

It is handy to have the functionality added in to ISE but is is rather simplistic  as indenting is not maintained where as the Sapien tool, while creating more complex HTML, does produce a more readable result.  To see the difference, here are some renditions of a command I have for trimming strings:

The ISE addin

function ConvertTo-CCTrimmedString

{

[CmdletBinding()]

Param

(

[Parameter(ValueFromPipeLine = $True,

   ValueFromPipelineByPropertyName = $true)]

[String[]]$String

)

Begin

{

}

Process

{

foreach ($s in $String)

{

$processedString = ($S.Trim().Split($null) |

Where-Object { -not [String]::IsNullOrWhiteSpace($PSItem) }) -Join ” “

Write-Output $processedString

}

}

End

{

}

}

 

PowerShell Studio

function ConvertTo-CCTrimmedString
{
    [CmdletBinding()]
    Param
    (
        [Parameter(ValueFromPipeLine = $True,
                   ValueFromPipelineByPropertyName = $true)]
        [String[]]$String
    )
    Begin
    {
    }
    Process
    {
        foreach ($s in $String)
        {
            $processedString = ($S.Trim().Split($null) |
            Where-Object { -not [String]::IsNullOrWhiteSpace($PSItem) }) -Join " "
            Write-Output $processedString
        }
    }
    End
    {
    }
}

To explain the command, unlike the Trim() method on a string which only removes the leading and trailing spaces from the string, my command also reduces multiple instances of white space characters within the string (spaces, tabs, end of line markers etc) to a single space.

I have been using Sapien’s tools for over 16 years now and continue to be impressed with the quality and functionality of their tools.

Advertisements

Entry filed under: PowerShell, Uncategorized.

Splitting command lines into command and arguments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

February 2017
M T W T F S S
« Jan    
 12345
6789101112
13141516171819
20212223242526
2728  

Most Recent Posts


%d bloggers like this: