{"id":2941,"date":"2010-06-04T18:52:00","date_gmt":"2010-06-04T18:52:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2010\/06\/04\/save-all-powershell-ise-files\/"},"modified":"2019-02-18T13:05:55","modified_gmt":"2019-02-18T20:05:55","slug":"save-all-powershell-ise-files","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/save-all-powershell-ise-files\/","title":{"rendered":"Save All PowerShell ISE files"},"content":{"rendered":"<p><span style=\"font-family: 'Arial','sans-serif';color: black\"><span style=\"font-size: small\">PowerShell ISE is a simple tool and in some cases it has the bare essentials. For instance, it does not have an option to save all files.<\/span><\/span><\/p>\n<p><span style=\"font-family: 'Arial','sans-serif';color: black\"><span style=\"font-size: small\"><span style=\"font-family: 'Arial','sans-serif';color: black\"><span style=\"font-size: small\"><span style=\"font-family: 'Arial','sans-serif';color: black\"><span style=\"font-size: small\">On the flipside, it offers an Object Model from its first version that allows adding features beyond the essentials like&nbsp;this one and many more.&nbsp;<\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p><span style=\"font-family: 'Arial','sans-serif';color: black\"><span style=\"font-size: small\"><\/p>\n<p><span style=\"font-family: 'Arial','sans-serif';color: black\"><span style=\"font-size: small\"><span style=\"font-family: 'Arial','sans-serif';color: black\"><span style=\"font-size: small\">If we had the &#8220;Save All&#8221; option in the ISE, one interesting question is what to do about untitled files.&nbsp;They are supposed to be transient. One could argue that Save All could just skip untitled files. Another could argue that we should just pick a name for untitled, but I would disagree with &#8220;another&#8221; \ud83d\ude42 Picking a name would soon fill some place in disk (which we would also have to pick) with a bunch of untitled files, which were supposed to be transient in the first place. We could prompt the user to pick a name for the untitled files, or show where we save them like we do in the PowerShell exit, but that doesn&rsquo;t look like the very autonomous Save All in other applications.<\/span><\/span><\/span><\/span><\/p>\n<p><\/span><\/span><\/p>\n<p><span style=\"font-family: 'Arial','sans-serif';color: black\"><span style=\"font-size: small\"><span style=\"font-family: 'Arial','sans-serif';color: black\"><span style=\"font-size: small\">The code below should be self explanatory and it skips untitled files as I thought better. <\/span><\/span><\/span><\/span><\/p>\n<p><span style=\"font-family: 'Arial','sans-serif';color: black\"><span style=\"font-size: small\"><span style=\"font-family: 'Arial','sans-serif';color: black\"><span style=\"font-size: small\">If you&nbsp;like it, you can add it to your profile (psedit $profile will edit the ISE profile) or to a module imported in your profile.<\/span><\/span><\/span><\/span><\/p>\n<p><p><span style=\"font-family: 'Arial','sans-serif';color: black\"><span style=\"font-size: small\"><span style=\"font-size: x-small\">Lucio Silveira [MSFT]<\/span><\/span><\/span><\/p>\n<\/p>\n<p><span style=\"font-family: Consolas;color: darkblue;font-size: 12pt\"><span style=\"font-family: Consolas;font-size: 12pt\"><span style=\"color: #000000\"><span style=\"font-family: Consolas;color: darkblue;font-size: 12pt\">function<\/span><span style=\"font-family: Consolas;font-size: 12pt\"> <span style=\"color: blueviolet\">Save-AllISEFiles<\/span><\/span><\/span><\/span><\/span><\/p>\n<p><p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\">{<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: darkgreen;font-size: 12pt\">&lt;#<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: darkgreen;font-size: 12pt\">.SYNOPSIS <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: darkgreen;font-size: 12pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>Saves all ISE Files except for untitled files. If You have <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>multiple PowerShellTabs, saves files in all tabs.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: darkgreen;font-size: 12pt\">#&gt;<\/span><span style=\"font-family: Consolas;font-size: 12pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\"><span>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: darkblue\">foreach<\/span>(<span style=\"color: orangered\">$tab<\/span> <span style=\"color: darkblue\">in<\/span> <span style=\"color: orangered\">$psISE<\/span><span style=\"color: darkgray\">.<\/span>PowerShellTabs)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>{<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: darkblue\">foreach<\/span>(<span style=\"color: orangered\">$file<\/span> <span style=\"color: darkblue\">in<\/span> <span style=\"color: orangered\">$tab<\/span><span style=\"color: darkgray\">.<\/span>Files)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: darkblue\">if<\/span>(<span style=\"color: darkgray\">!<\/span><span style=\"color: orangered\">$file<\/span><span style=\"color: darkgray\">.<\/span>IsUntitled)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: orangered\">$file<\/span><span style=\"color: darkgray\">.<\/span>Save()<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>}<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>}<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>}<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\">}<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 12pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: darkgreen;font-size: 12pt\"># This line will add a new option in the Add-ons menu to save all ISE files with the Ctrl+Shift+S shortcut. <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: darkgreen;font-size: 12pt\"># If you try to run it a second time it will complain that Ctrl+Shift+S is already in use<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;color: orangered;font-size: 12pt\">$psISE<\/span><span style=\"font-family: Consolas;color: darkgray;font-size: 12pt\">.<\/span><span style=\"font-family: Consolas;font-size: 12pt\">CurrentPowerShellTab<span style=\"color: darkgray\">.<\/span>AddOnsMenu<span style=\"color: darkgray\">.<\/span>Submenus<span style=\"color: darkgray\">.<\/span>Add(<span style=\"color: darkred\">&#8220;Save All&#8221;<\/span><span style=\"color: darkgray\">,<\/span>{<span style=\"color: blue\">Save-AllISEFiles<\/span>}<span style=\"color: darkgray\">,<\/span><span style=\"color: darkred\">&#8220;Ctrl+Shift+S&#8221;<\/span>)<\/span><\/p>\n<\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Calibri;font-size: small\"><span style=\"font-family: Calibri;font-size: small\"><\/p>\n<p><p class=\"MsoNormal\">&nbsp;<\/p>\n<\/p>\n<p><\/span><\/span><\/p>\n<p><p class=\"MsoNormal\">&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell ISE is a simple tool and in some cases it has the bare essentials. For instance, it does not have an option to save all files. On the flipside, it offers an Object Model from its first version that allows adding features beyond the essentials like&nbsp;this one and many more.&nbsp; If we had the [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[260,270],"class_list":["post-2941","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-powershell-ise","tag-powershell-v2"],"acf":[],"blog_post_summary":"<p>PowerShell ISE is a simple tool and in some cases it has the bare essentials. For instance, it does not have an option to save all files. On the flipside, it offers an Object Model from its first version that allows adding features beyond the essentials like&nbsp;this one and many more.&nbsp; If we had the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/2941","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=2941"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/2941\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=2941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=2941"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=2941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}