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)?
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)?
New tab:
$tab = $psISE.PowerShellTabs.Add()
Load script file to new tab:
$tab.Files.Add("full_path_to_script_file.ps1")
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 *
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