{"id":3603,"date":"2013-05-19T00:01:00","date_gmt":"2013-05-19T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/05\/19\/weekend-scripter-add-power-and-functionality-to-the-powershell-ise-part-2\/"},"modified":"2013-05-19T00:01:00","modified_gmt":"2013-05-19T00:01:00","slug":"weekend-scripter-add-power-and-functionality-to-the-powershell-ise-part-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-add-power-and-functionality-to-the-powershell-ise-part-2\/","title":{"rendered":"Weekend Scripter: Add Power and Functionality to the PowerShell ISE Part 2"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary<\/strong><span style=\"font-size: 12px\">: Microsoft Scripting Guy, Ed Wilson, adds more power and functionality to the Windows PowerShell ISE with a modified module.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. This is Part 2 of a two part series where I edit my Windows PowerShell ISE module and add five new functions. The five new functions are:<\/p>\n<ul>\n<li>Add-RemarkedText<\/li>\n<li>Remove-MarkedText<\/li>\n<li>Edit-Module<\/li>\n<li>Import-EveryModule<\/li>\n<li>Switch-OutLineView<\/li>\n<\/ul>\n<p>Yesterday, in <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/05\/18\/weekend-scripter-add-power-and-functionality-to-the-powershell-ise.aspx\">Add Power and Functionality to the PowerShell ISE Part 1<\/a>, I talked about the <strong>Add-RemarkedText<\/strong> and the <strong>Remove-MarkedText<\/strong> functions. Today I am going to talk about the remaining three functions.<\/p>\n<h2>The Edit-Module function<\/h2>\n<p>The <strong>Edit-Module<\/strong> function is a function that I have wanted to write for a long time. The scenario goes like this: I am in the Windows PowerShell ISE working on a script. I realize I want to add or to edit something to an installed Windows PowerShell module. So I have to click around and find the module, and then open it in the Windows PowerShell ISE so I can check something or edit something in the module.<\/p>\n<p>Granted, it is not a huge problem, but it does slow things down a bit. Slow no longer&mdash;not with my <strong>Edit-Module<\/strong> function. To use it, all I need to do is type <strong>Edit-Module<\/strong> (<strong>em<\/strong> is an alias), and provide enough of the module name to distinguish it to Windows PowerShell. Yes, this function uses wildcard characters. For example, if I want to edit my PowerShellIseModule.psm1 file, I can type all of that, or I can just type <strong>PowerShell*<\/strong> (on my system) to gain access to the file. This technique is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2867.hsg-5-19-13-01.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2867.hsg-5-19-13-01.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Here is the complete <strong>Edit-Module<\/strong> function:<\/p>\n<p style=\"padding-left: 30px\"><strong>Edit-Module<\/strong><\/p>\n<p style=\"padding-left: 30px\">Function Edit-Module<\/p>\n<p style=\"padding-left: 30px\">{<\/p>\n<p style=\"padding-left: 30px\">&nbsp; &lt;#<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Synopsis<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; This opens a module stored in the $env:PSModulePath location on a new tab in ISE<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Description<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; This function uses Get-Module to retrieve a module from $env:PSModulePath and then<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; it opens the module from that location into a new tab in ISE for editing. Wildcard<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; characters that resolve to a single module are supported.<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Example<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Edit-Module PowerShellISEModule<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Edit-Module PowerShellISEModule opens the PowerShellISEModule into a new tab in the<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; ISE for editing<\/p>\n<p style=\"padding-left: 30px\">&nbsp; .Example<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Edit-Module PowerShellISE*<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Edit-Module PowerShellISE* opens the PowerShellISEModule into a new tab in the<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; ISE for editing by using a wild card character for the module name<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Parameter Name<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; The name of the module. Wild cards that resolve to a single module are supported<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Notes<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; NAME:&nbsp; Edit-Module<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; AUTHOR: ed wilson, msft<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; LASTEDIT: 05\/16\/2013 18:14:19<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; KEYWORDS: Scripting Techniques, Modules<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; HSG: WES-5-18-2013<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Link<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp; Http:\/\/www.ScriptingGuys.com<\/p>\n<p style=\"padding-left: 30px\">&nbsp;#Requires -Version 2.0<\/p>\n<p style=\"padding-left: 30px\">&nbsp;#&gt;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Param($name)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;ISE (Get-Module -ListAvailable $name).path<\/p>\n<p style=\"padding-left: 30px\">} #end function Edit-Module<\/p>\n<h2>Importing every module<\/h2>\n<p>Yes, there are times when I need to import every module in Windows PowerShell. I used to type the following command:<\/p>\n<p style=\"padding-left: 30px\">Get-Module &ndash;ListAvailable | Import-Module<\/p>\n<p>Even with aliases such as <strong>gmo<\/strong> and <strong>ipmo<\/strong>, the command got a bit tedious. So I finally decided to quit typing that command by creating my <strong>Import-EveryModule<\/strong> function. The previous code is the gist of the function,&mdash;he remainder is the gravy. Here is the complete function:<\/p>\n<p style=\"padding-left: 30px\"><strong>Import-EveryModule<\/strong><\/p>\n<p style=\"padding-left: 30px\">Function Import-EveryModule<\/p>\n<p style=\"padding-left: 30px\">{<\/p>\n<p style=\"padding-left: 30px\">&nbsp; &lt;#<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Synopsis<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; This imports all modules from the $env:PSModulePath<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Description<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; This function imports all modules from $env:psmodulepath<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Example<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Import-EveryModule<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Import-EveryModule imports all modules from $env:psmodulepath<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Notes<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; NAME:&nbsp; Import-EveryModule<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; AUTHOR: ed wilson, msft<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; LASTEDIT: 05\/16\/2013 18:24:26<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; KEYWORDS: Scripting Techniques, Modules<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; HSG: Wes-5-18-2013<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Link<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp; Http:\/\/www.ScriptingGuys.com<\/p>\n<p style=\"padding-left: 30px\">&nbsp;#Requires -Version 2.0<\/p>\n<p style=\"padding-left: 30px\">&nbsp;#&gt;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Get-Module -ListAvailable |<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Import-Module -Force<\/p>\n<p style=\"padding-left: 30px\">} #end function Import-Everymodule<\/p>\n<p><span style=\"font-size: 12px\">To make it easier to call this useful bit of code, I create an alias <\/span><strong style=\"font-size: 12px\">iem<\/strong><em style=\"font-size: 12px\"> <\/em><span style=\"font-size: 12px\">for <\/span><strong style=\"font-size: 12px\">Import-EveryModule<\/strong><span style=\"font-size: 12px\">.<\/span><\/p>\n<h2>Toggling the Outline view in the Windows PowerShell ISE<\/h2>\n<p>The last function I want to talk about is the <strong>Switch-OutlineView<\/strong> function. What this function does is toggle the Outline view in the current Windows PowerShell ISE script pane. This function is very helpful when working on a long script (such as the 500+ line PowerShellISEModule.PSM1 file). The best way to show this is to show you the script pane with the Outline view set to On:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3146.hsg-5-19-13-02.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3146.hsg-5-19-13-02.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Now I can expand the Outline view to full code mode by typing <strong>Switch-OutlineView<\/strong> in the execution pane (<strong>sov<\/strong> is an alias that I created for this).<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3326.hsg-5-19-13-03.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3326.hsg-5-19-13-03.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Here is the complete text of the <strong>Switch-OutlineView<\/strong> function:<\/p>\n<p style=\"padding-left: 30px\"><strong>Switch-OutlineView<\/strong><\/p>\n<p style=\"padding-left: 30px\">Function Switch-OutlineView<\/p>\n<p style=\"padding-left: 30px\">{<\/p>\n<p style=\"padding-left: 30px\">&nbsp; &lt;#<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Synopsis<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; This function toggles the outline view in the ISE<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Description<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; This function toggles the outline view in the ISE. It will expand<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; or collapse all functions in the current script pane.<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Example<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Switch-OutlineView<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Switch-OutlineView will either expand or collapse all functions<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Notes<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; NAME:&nbsp; Switch-OutlineView<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; AUTHOR: ed wilson, msft<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; LASTEDIT: 05\/16\/2013 19:28:37<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; KEYWORDS: Scripting Techniques, Modules<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; HSG: wes-5-18-2013<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; .Link<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp; Http:\/\/www.ScriptingGuys.com<\/p>\n<p style=\"padding-left: 30px\">&nbsp;#Requires -Version 3.0<\/p>\n<p style=\"padding-left: 30px\">&nbsp;#&gt;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;$psise.CurrentFile.Editor.ToggleOutliningExpansion()<\/p>\n<p style=\"padding-left: 30px\">} #end function switch-outlineview<\/p>\n<p>The revised PowerShellISEModule and profile is available via the Scripting Guys Script Repository:&nbsp;<a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/Windows-PowerShell-ISE-ff235827\" target=\"_blank\">Windows PowerShell ISE Profile and Modules<\/a>.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong><span style=\"font-size: 12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, adds more power and functionality to the Windows PowerShell ISE with a modified module. Microsoft Scripting Guy, Ed Wilson, is here. This is Part 2 of a two part series where I edit my Windows PowerShell ISE module and add five new functions. The five new functions are: Add-RemarkedText [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[52,3,4,61,45],"class_list":["post-3603","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-modules","tag-scripting-guy","tag-scripting-techniques","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, adds more power and functionality to the Windows PowerShell ISE with a modified module. Microsoft Scripting Guy, Ed Wilson, is here. This is Part 2 of a two part series where I edit my Windows PowerShell ISE module and add five new functions. The five new functions are: Add-RemarkedText [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=3603"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3603\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=3603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}