How can I open a ps1 script in Powershell ISE from the command line?

Tag: powershell Author: dianjing200336 Date: 2009-08-10

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)?

Wow, I can't believe someone is as much a stickler as me to have asked this one before. Kudos!

Best Answer

psEdit filename


both solutions work, but this is the easiest. Thank!

Other Answer1

PowerShell 2.0 in Windows 7, PSEdit does not work. Use "ise", which is an alias for powershell_ise.exe.

ex. ise .\myscript.ps1


+1. I could use the ex. portion (new to PS)
+1 When working in the standard PS console, this is the way to open a file in the ISE.

Other Answer2

Programmatically, this works:


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

Get-Command PSEdit | Format-List *

Other Answer3

I took the psedit command and allowed input from the pipeline

Function psedit {
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


Other Answer4

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

Load script file to new tab: