tags:

views:

438

answers:

4

I'm trying to figure out how I can open a ps1 script (or any file) in PS ISE by using the $psISE object.

How can I open a document tab in PS ISE from the command line in PS ISE itself (without using File > Open)?

A: 

New tab:
$tab = $psISE.PowerShellTabs.Add()

Load script file to new tab:
$tab.Files.Add("full_path_to_script_file.ps1")

Shay Levy
+4  A: 

psEdit filename

Doug Finke
both solutions work, but this is the easiest. Thank!
spoon16
+1  A: 

Programmatically, this works:

$psISE.CurrentPowerShellTab.Files.Add("$pwd\foo.ps1")

Which is essentially what the PSEdit function uses. To see this execute:

Get-Command PSEdit | Format-List *
Keith Hill
+2  A: 

I took the psedit command and allowed input from the pipeline

Function psedit {
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]$filenames)
foreach ($filename in $filenames)
    {
        dir $filename | where {!$_.PSIsContainer} | %{
            $psISE.CurrentPowerShellTab.Files.Add($_.FullName) > $null
        }
 }     
 }

This allows me to something like this

7 >  ls test*.ps1 | psedit

I find this useful when working on modules and I have several scripts in a directory

Andy

Andy Schneider