Using Help Window as Text Dialog

by May 10, 2013

Did you know that you can use the Help Window that comes with PowerShell 3.0 and display your own text information inside of it? What's even better: the help window will support full text searches in the text you display and highlight any matching text, just like with PowerShell help topics.

Note: the code works immediately in PowerShell 3.0 ISE editor. If you want to run it in the PowerShell 3.0 console, you need to first load the necessary assembly like this:

Add-Type -AssemblyName Microsoft.PowerShell.GraphicalHost

Here's the code (it displays text found in winrm.ini but you can display any text – just assign it to $text).

$text = Get-Content $env:windir\system32\winrm\*\winrm.ini -ReadCount 0 | Out-String

$HelpWindow = New-Object Microsoft.Management.UI.HelpWindow $text -Property @{
    Title="My Text Viewer"
    Background='#011f51'
    Foreground='#FFFFFFFF'
}

$HelpWindow.ShowDialog()

Twitter This Tip! ReTweet this Tip!