Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Friday Fun: Save All Open PowerShell ISE Files

Posted on August 3, 2012August 2, 2012

Here's a little tidbit that I previously shared on Twitter and Google Plus. The PowerShell ISE obviously has a Save menu choice. But there's no menu option to save all open files. But you can add one yourself. All of the open files are part of the $psise.CurrentPowerShellTab.Files collection. Each item has a Save() method so to save all the files all you need to do is enumerate the collection ForEach and invoke the Save() method. You could run a command like this in the command prompt of the ISE.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!


$psise.CurrentPowerShellTab.files | foreach {
$_.Save()
}

Where you will run into problems is with files that have not been saved yet and are still untitled. This code will throw exceptions. The solution is to simply skip untitled files.


$psise.CurrentPowerShellTab.files |
where {-Not ($_.IsUntitled)} |
foreach {
$_.Save()
}

You can save untitled files with the SaveAs() method but you have to provide a file name. I can't find anyway to easily invoke the GUI prompt so for now I have manually save untitled files.

Now, instead of running this command every time, let's add it to the ISE Add-Ons menu.


$sb={
$psise.CurrentPowerShellTab.files |
where {-Not ($_.IsUntitled)} |
foreach {
$_.Save()
}
}

$psise.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Save All Files",$sb,"Ctrl+Shift+A") | out-null

I even added a keyboard shortcut. Add these lines to your PowerShell ISE profile and you'll always have this menu option. Or download Add-SaveAllISE.ps1 and load the script in your profile. As far as I can tell this works in both PowerShell v2 and v3.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

2 thoughts on “Friday Fun: Save All Open PowerShell ISE Files”

  1. davecarnahan says:
    August 7, 2012 at 12:34 am

    Interesting. Jeffrey thanks!
    What other little Easter eggs, does ISE have?

    1. Jeffery Hicks says:
      August 7, 2012 at 8:26 am

      Explore the $psise object.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d