Solution Explorer for PowerShell ISE

The PowerShell ISE is a fine environment for writing PowerShell scripts, but handling a large number of files becomes a chore with using the common open dialog and tabs to manage files.  The PowerShell ISE also supports add-on panes, so I put together a little file explorer pane that lists all the ps1 and psm1 files under the PowerShell profile.  To do this I leveraged ShowUI.  The version of ShowUI that I downloaded had a bug in Modules\ShowUI\ConvertTo-ISEAddOn.ps1, it needs to add the to the correct pane instead of always adding to HorizontalAddOnTools:

if ($addHorizontally) {
} elseif ($addVertically) {
} else {

Make sure that bug is correct in your copy before running the below script.  I created a new Module ISEFileExplorer, and also included my copy of ShowUI.  You can download the source for both modules.

ConvertTo-ISEAddOn -DisplayName "File Explorer" -ScriptBlock {
    function Parse-Directory($dir) {
        $dname = (Split-Path -Leaf $dir)
        # Exclude some common modules.
        if ($dname -in @("ShowUI", "PowerTab", "SQLite")) { return }
        $item = New-TreeViewItem -Header $dname
        if ($dname -eq "WindowsPowerShell") { $item.IsExpanded = $true }
        foreach($obj in ls $dir) {
            if ($obj.PSIsContainer) {
                $d = (Parse-Directory $obj.FullName)
                if ($d) {
                    $item.items.Add($d) | Out-Null
            } else {
                if ($obj.Name -like "*.ps1" -or 
                    $obj.Name -like "*.psm1") {
                    $item.items.Add((New-TreeViewItem -tag $obj.FullName -Header $obj.Name  -Foreground (new-object System.Windows.Media.SolidColorBrush ([System.Windows.Media.Colors]::DarkBlue)))) | Out-Null
        if ($item.items.Count -eq 0) { return } # Exclude empty folders
    New-TreeView -Items (Parse-Directory "$HOME\Documents\WindowsPowerShell") -On_SelectedItemChanged { 
        if ($args.NewValue.Tag) {
    } -FontSize ($psISE.Options.FontSize * ($psISE.Options.Zoom / 100.0)) -Padding 0 -Margin 0 -BorderThickness 0
} -AddVertically -Visible

The script is very simple, it creates a WPF TreeView control, and populates it with all the .ps1 and .psm1 files under the PowerShell home directory.  Directories are colored in black, and files are in blue.  Empty folders are hidden, and there’s a small exclusion list for common modules.  A single-click on a file will open or switch it into focus.  The font size is based on the font the ISE is configured to use, as well as the zoom level when the panel is initialized.  There’s a small hang in the ISE when the control loads, I’m unsure how to remove it due to the threading of UI controls.

Here’s what it looks like:

PowerShell ISE showing the ISEFileExplorer addon

March 17, 2013