Tome's Land of IT

IT Notes from the Powertoe – Tome Tanasovski

Open a file in Powershell ISE via cmdlet

Today I found myself annoyed at the process I have to go through to open a script while working in ISE.   I decided to put together a quick cmdlet that will make this very easy.  I used the technique from my last post to ensure that I could pipe in a collection of scripts to open at once.  Perhaps I’ll grow this module with time, but for now you can download it with the single cmdlet here (Make sure to unblock the .zip prior to extracting).  I’ve also uploaded the code behind the function to Poshcode.

Here is the contents of get-help open-ISEFile -full:

NAME
    Open-ISEFile

SYNOPSIS
    Open a new file in ISE

SYNTAX
    Open-ISEFile [-Path]  [-PassThru] []

DESCRIPTION
    This cmdlet allows you to open a file in a new file tab within your current Powershell t
    ab.  You can pass a collection of files to open more than one file.

PARAMETERS
    -Path 
        Specifies a path to one or more files.  Wildcards are permitted.  The default locati
        on is the current directory (.).

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?       true (ByValue)
        Accept wildcard characters?  

    -PassThru []

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  

        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        "get-help about_commonparameters".

INPUTS
    System.String

OUTPUTS
    None or Microsoft.PowerShell.Host.ISE.ISEFile

    When you use the PassThru parameter, Open-ISEFile returns a Microsoft.PowerShell.Host.IS
    E.ISEFile for each file opened.  Otherwise, this cmdlet does not generate any output.

NOTES

        Name: Open-ISEFile
        Author: Tome Tanasovski
        Created: 6/20/2010
        Version: 1.0

    -------------------------- EXAMPLE 1 --------------------------

    C:\PS>Open-ISEFile -Path $profile

    Opens your profile in ISE.

    -------------------------- EXAMPLE 2 --------------------------

    C:\PS>dir *.ps1 |Open-ISEFile

    Opens up all ps1 files in the current directory as new file tabs in ISE.

    -------------------------- EXAMPLE 3 --------------------------

    C:\PS>Open-ISEFile *.ps1

    Opens up all ps1 files in the current directory as new file tabs in ISE.

    -------------------------- EXAMPLE 4 --------------------------

    C:\PS>$file = Open-ISEFile "c:\file1.ps1" -PassThru

    Opens up file1.ps1 in ISE.  The command uses the passthru parameter to generate an objec
    t that represents a file in ISE.

RELATED LINKS
     https://powertoe.wordpress.com
Advertisements

One response to “Open a file in Powershell ISE via cmdlet

  1. Ben June 27, 2010 at 10:34 am

    I have been using “psedit” in my profile or to edit files.

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

%d bloggers like this: