Configuring the ISE

I tend to flatten my laptop about once a season. Among the other things I lose is my PowerShell_ISE customizations. They’re not many, but I miss them when I have to live without them. Fortunately, they’re all captured in my Microsoft.PowerShellISE_profile.ps1:

#$PSModuleAutoLoadingPreference = 'None';

@(

    "C:\Users\timdunn\Config\PSHModules\ISESteroidsV1\ISESteroids.psd1",

    "C:\Users\timdunn\Config\PSHModules\PSReadLine\PSReadline.psd1"

) |

%{

    if (Test-Path -Path $_) { Import-Module $_; }

}

if (Test-Path -Path "C:\Users\timdunn\Config\PSHModules\Windows PowerShell ISE V3 Copy As HTML Add-On\Falchion.PowerShell.CopyAsHtmlAddOn.dll")

{

    Add-Type -Path "C:\Users\timdunn\Config\PSHModules\Windows PowerShell ISE V3 Copy As HTML Add-On\Falchion.PowerShell.CopyAsHtmlAddOn.dll";

    $copyAsHtmlAddOn = New-Object Falchion.PowerShell.CopyAsHtmlAddOn.CopyAsHtml

    $copyAsHtmlAddOn.HostObject = $psISE

    try

    {

        $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Copy as HTML", { $copyAsHtmlAddOn.Copy() }, "CTRL+SHIFT+C") | Out-Null

    }

    catch

    {

    }

}

function prompt

{

    "`n# $($env:USERDNSDOMAIN.ToLower())\$env:UserName@$env:computerName.$((Get-WmiObject Win32_ComputerSystem).Domain) ".ToLower() + $(

        if ($history = Get-History | Select-Object -last 1)

        {

            ($history.EndExecutionTime - $history.StartExecutionTime).ToString() -replace "\..*";

        }

        else

        {

            "00:00:00";

        }

    ) + " ($([int]((Get-History | Select-Object -Last 1).ID) + 1))`n# $(Get-Location) $(Get-Date -Format 'yyyy-MM-dd_HH.mm.ss') $('>' * $nestedpromptlevel)> `n";

}

cd $home;

$Error.Clear();

As you can see, I use ISESteroids, PSReadline, and Copy As HTML. The first one is payware, but I find it useful. PSReadline is actually more intended for console use; the command console under ISE is pretty good, but it lacks the concept of a $Host.Ui.RawUI.WindowSize, so stuff like pagination doesn’t work. Finally, Cop yAs HTML is the reason I’m writing this post. I’ve used probably three syntax formatters for PSH-to-HTML in the past, but seem to los them each time. Bing searches return ways to output HTML from PowerShell, or to use PSH to drive some other product to pretty-print HTML.

The past few articles saw me using hilite.me. It’s good, but insists on putting a red rectangle around my trailing semicolons, so I wanted to move off it and onto something better.