Home > PowerShell > Until PowerShell ISE gets PowerGUI’s “Open Profile” feature…

Until PowerShell ISE gets PowerGUI’s “Open Profile” feature…

I hate to admit it, but the convenience of having PowerShell ISE installed with the core installation of PowerShell 2.0 has been enough to get me to switch from PowerGUI, which is in my opinion a much more full featured free editor/debugger.

One thing that I sorely missed from PowerGUI (which is compounded by the fact that unless you’re on Windows 7, PowerShell ISE doesn’t have a "Recent Files" menu) is the ability to quickly open my profile script without having to browse for it.

Well PowerShell ISE is extensible, so if it lacks a feature, you can just add it in most cases. I’ve uploaded my PowerShell ISE profile which has some useful functions for automating the ISE. But the one in particular that implements the "Open Profile" feature is called….(wait for it)…. Open-Profile!

So you can type that in the immediate window, or use the custom menu item that gets added. It opens the user/global/host/generic/etc profiles if they exist.

http://cid-89e05724af67a39e.skydrive.live.com/embedrowdetail.aspx/PowerShell/Microsoft.PowerShellISE|_profile.ps1

function Open-File([String]$Path,[Switch]$Quiet) {

    $AllowedExtensions = @('.ps1','.psm1','.psd1','.ps1xml','.txt','.txt')
    $Extension = [System.IO.Path]::GetExtension($Path)

    try {

        if ( -not ($AllowedExtensions -contains $Extension) ) { throw "OpenFile: $Path cannot be opened in PowerShell ISE." }
        if ( -not (Test-Path $Path) ) { throw "OpenFile: $Path does not exist." }
        
        $Path = (Resolve-Path $Path).ProviderPath
        $PSISE.CurrentOpenedRunspace.OpenedFiles.Add($Path)
        
    }
    catch {
        if ( -not $Quiet ) { Write-Warning $_ }
    }

}

function Open-Profile {
    Open-File $PROFILE.CurrentUserAllHosts -Quiet
    Open-File $PROFILE.CurrentUserCurrentHost -Quiet
    Open-File $PROFILE.AllUsersAllHosts -Quiet
    Open-File $PROFILE.AllUsersCurrentHost -Quiet
}
Categories: PowerShell
  1. Trevor
    November 15, 2009 at 8:49 pm | #1

    In my opinion, the PowerShell ISE is inferior to PowerGUI for a variety of reasons. One of those reasons is the lack of the variable browser pane, which PowerGUI features. This is a very nice debugging benefit of the PowerGUI IDE.-Trevor Sullivan

  1. No trackbacks yet.

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.