Как запустить Powershell ISE без открытого файла?

846
Billy ONeal

Когда я запускаю powershell_ise.exe, он по умолчанию имеет открытый файл "Untitled.ps1". Есть ли механизм, чтобы попросить ISE запустить, показывая только приглашение?

То есть в тот момент, когда я запускаю Powershell ISE, я получаю следующее:

Powershell с пустым документом

тогда как я хочу следующее:

Powershell без документов

2
Почему бы вам просто не запустить PowerShell? Tanner Faulkner 9 лет назад 0
@Tanner: поддержка Unicode, intellisense, более быстрое эхо и т. Д. Billy ONeal 9 лет назад 1
Вы имеете в виду, как это: http://i.imgur.com/yr3xSRu.png - Это мой стандарт по умолчанию для Windows 8 ISE, только с консолью? Samuel Nicholson 9 лет назад 0

3 ответа на вопрос

2
jerbil24

Очень старый вопрос на данный момент, но я просто отказался от @Windos, чтобы найти решение, которое работает для меня. Так как я использую стероиды ISE, есть функция сохранения открытых файлов. Я не хотел закрывать все открытые файлы при запуске, только Untitled.

foreach($file in $psISE.CurrentPowerShellTab.Files) { if ($file.DisplayName -like "Untitled*.ps1"){ $deleteMe = $file } } $psISE.CurrentPowerShellTab.Files.Remove($deleteMe) 

Попытка удалить файл в цикле for приведет к ошибке перечисления. Если при запуске открываются несколько сценариев без названия, это $deletemeможет быть массив, который добавляет несколько собственных файлов, foreachчтобы удалить все из них.

1
Keltari

Just adjust your View settings in the menu.

  • Uncheck Show Script pane
  • Uncheck Show Command Add-On
  • Uncheck Show Toolbar
  • Uncheck other options as desired

enter image description here

Мог бы поклясться, что я попробовал это. Если вы закроете все экземпляры ISE и начнете снова, это помнит? Billy ONeal 9 лет назад 0
У меня сработало Keltari 9 лет назад 0
1
Windos

This is an old question now, but I came here looking for an answer so figured I'd give the results of my experimentation.

There is a $psISE object which controls ISE settings, the open files, etc. There is a lot you can do with it.

There was a promising looking function:

$psISE.CurrentPowerShellTab.Files.Clear() 

Unfortunately, this would simply close all open files (if they were saved) and then open a new untitled file.

I ended up with this:

$null = while ($psISE.CurrentPowerShellTab.Files -ne $null) { $file = $psISE.CurrentPowerShellTab.Files[0] $psISE.CurrentPowerShellTab.Files.Remove($file) } 

Basically, it keeps checking the open files, and closes them until there are none left open. If you were to run this interactively, and had an unsaved document open, you'd be flooded by error pretty quickly as it fails to close then loops back to trying to close it again.

You can then put this in your ISE profile (C:\username\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1). This is what my profile looks like at the moment:

$null = while ($psISE.CurrentPowerShellTab.Files -ne $null) { $file = $psISE.CurrentPowerShellTab.Files[0] $psISE.CurrentPowerShellTab.Files.Remove($file) } psEdit $PSScriptRoot\snips.ps1 

Since this runs when launching the ISE, it closes the default untitled file and opens a random file with little snippets I like to refer to instead. You could omit that last line or change it to any file you want to open.

n.b. that $null = is in there to suppress output, and it is faster than piping to Out-Null (which I think is important when you're waiting for your editor to load.)