{"id":11221,"date":"2012-02-07T00:01:00","date_gmt":"2012-02-07T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/02\/07\/learn-how-to-use-the-free-powershell-ise-to-edit-scripts\/"},"modified":"2012-02-07T00:01:00","modified_gmt":"2012-02-07T00:01:00","slug":"learn-how-to-use-the-free-powershell-ise-to-edit-scripts","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/learn-how-to-use-the-free-powershell-ise-to-edit-scripts\/","title":{"rendered":"Learn How to Use the Free PowerShell ISE to Edit Scripts"},"content":{"rendered":"<p><b>Summary<\/b>: Learn about using the Windows PowerShell ISE to edit scripts, and to modify the script execution policy in this step-by-step blog.<\/p>\n<p><span><span><span><span><span><span><span><span><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\" \/><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>&nbsp;Hey, Scripting Guy! I have a problem. I was following your blog yesterday about <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/02\/06\/use-the-powershell-ise-to-work-with-long-commands.aspx?CommentPosted=true#commentmessage\" target=\"_blank\">&nbsp;typing long commands inside the Windows PowerShell ISE<\/a>, and I saved my work because I did not want to lose what I was working on, and all of a sudden I could no longer do anything. Is this a bug?<\/p>\n<p>&mdash;BW<\/p>\n<p><span><span><span><span><span><span><span><span><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\" \/><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>Hello BW,<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. This week I have been working diligently on the events for the <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/02\/04\/the-2012-windows-powershell-scripting-games-all-links-on-one-page.aspx\" target=\"_blank\">2012 Scripting Games<\/a>. The Scripting Wife and I have also been working on the first ever <a href=\"http:\/\/powershellgroup.org\/content\/powershell-saturday\">PowerShell Saturday<\/a> in Columbus, Ohio. At this event, I will be presenting a number of &ldquo;beginning with Windows PowerShell&rdquo;<i> <\/i>type of presentations. There will also be presentations about using Windows PowerShell with Active Directory, SharePoint, and even Exchange Server. There will be several special guest presentations from a world class grouping of speakers. If you are anywhere near Columbus, Ohio, you do not want to miss this event. Seating is limited, and available slots are going quickly.<\/p>\n<p>Anyway, BW, one of the skills you will need to know about for the 2012 Scripting Games is how to use a script editor. Because the Windows PowerShell ISE comes free, you may as well learn how to use it. If you feel that it is limited, keep in mind that it can be extended. I have talked quite a bit about <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/windows+powershell+ise\/\" target=\"_blank\">using the Windows PowerShell ISE object model to extend capabilities<\/a>, and I have written a number of add-ins to assist me in working with modules, replacing aliases in scripts, adding command snip-its, and more.<\/p>\n<p>BW, after you save the code in the Windows PowerShell ISE, it becomes a script. When this happens, you run afoul of the script execution policy on your computer. In the image that follows, a simple Windows PowerShell script (now saved) does not execute because the script execution policy does not permit running scripts.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4186.hsg-2-7-12-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4186.hsg-2-7-12-1.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>I have discussed the Windows PowerShell script execution policy on several occasions. In one blog, I helped the Scripting Wife <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/04\/18\/hey-scripting-guy-april-18-2010.aspx\" target=\"_blank\">set the script execution policy<\/a> on her computer. On another occasion, posted an excerpt from my best selling <a href=\"http:\/\/www.amazon.com\/Windows-PowerShell-2-0-Best-Practices\/dp\/0735626464\/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1255959455&amp;sr=8-1\" target=\"_blank\">Windows PowerShell 2.0 Best Practices book<\/a> titled <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2009\/11\/24\/hey-scripting-guy-november-24-2009.aspx\" target=\"_blank\">Why Would I Even Want to Create a Profile in Windows PowerShell?<\/a><\/p>\n<p>Now, the network administrator via Group Policy might set the script execution policy, but it might also not be set. By default, Windows PowerShell disables the execution of scripts. This means you can use Windows PowerShell to run commands, but you cannot run a script. To set the script execution policy for all Windows PowerShell hosts and for all users of the computer requires administrator rights. But a normal user can modify the execution policy for the current Windows PowerShell host and for the current user by specifying the scope of <i>CurrentUser<\/i>. The command to permit running scripts for the current user is shown here.&nbsp;&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Set-ExecutionPolicy -ExecutionPolicy remotesigned -Scope currentuser -Force<\/p>\n<p>In the image that follows, the previous command runs to permit the execution of Windows PowerShell scripts. The change takes effect immediately, and it does not require a reboot or the closing and reopening the Windows PowerShell ISE.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5482.hsg-2-7-12-2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5482.hsg-2-7-12-2.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>It does not take too long before output seems to clutter the output pane. In general, when I am developing a script, I like to clear the output pane after each run of the script so I can easily identify any newly appearing error messages. There are two ways to clear the output pane. The first is to use the &ldquo;windshield washer&rdquo; icon that appears in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5282.hsg-2-7-12-3.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5282.hsg-2-7-12-3.png\" alt=\"Image of toolbar\" title=\"Image of toolbar\" \/><\/a><\/p>\n<p>The other way to clear the output pane is to use the same command that works for the Windows PowerShell console&mdash;the <b>Clear-Host<\/b> command. The <b>Clear-Host<\/b> command has two aliases: <i>clear <\/i>and <i>cls. <\/i>I found these aliases by using the <b>Get-Alias<\/b> cmdlet as shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\Users\\ed&gt; Get-Alias -Definition clear-host<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">CommandType&nbsp;&nbsp;&nbsp;&nbsp; Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Definition<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">Alias&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clear&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Clear-Host<\/p>\n<p style=\"padding-left: 30px\">Alias&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cls&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Clear-Host<\/p>\n<p>To use the <b>Clear-Host <\/b>command (or the <i>cls <\/i>or <i>clear <\/i>alias for the command), type it in the command pane, as illustrated in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2364.hsg-2-7-12-4.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2364.hsg-2-7-12-4.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>If I need to edit the script, there are <i>Cut<\/i>,<i> Copy<\/i>, and <i>Paste<\/i> commands available in the tool bar. Because the Windows PowerShell ISE is a standard Windows type of application, there are also the following shortcuts to assist you in quickly editing your script with the ISE.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"319\" valign=\"top\">\n<p><b>Command<\/b><\/p>\n<\/td>\n<td width=\"319\" valign=\"top\">\n<p><b>Keyboard shortcut<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">\n<p>Copy<\/p>\n<\/td>\n<td width=\"319\" valign=\"top\">\n<p>Ctrl + c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">\n<p>Cut<\/p>\n<\/td>\n<td width=\"319\" valign=\"top\">\n<p>Ctrl + x<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">\n<p>Paste<\/p>\n<\/td>\n<td width=\"319\" valign=\"top\">\n<p>Ctrl + v<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">\n<p>Undo<\/p>\n<\/td>\n<td width=\"319\" valign=\"top\">\n<p>Ctrl + z<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">\n<p>Redo<\/p>\n<\/td>\n<td width=\"319\" valign=\"top\">\n<p>Ctrl + y<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">\n<p>Find (in script)<\/p>\n<\/td>\n<td width=\"319\" valign=\"top\">\n<p>Ctrl + f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">\n<p>Find Next (in script)<\/p>\n<\/td>\n<td width=\"319\" valign=\"top\">\n<p>F3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">\n<p>Find Previous (in script)<\/p>\n<\/td>\n<td width=\"319\" valign=\"top\">\n<p>Shift + F3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">\n<p>Replace (in script)<\/p>\n<\/td>\n<td width=\"319\" valign=\"top\">\n<p>Ctrl + H<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">\n<p>Go To Line<\/p>\n<\/td>\n<td width=\"319\" valign=\"top\">\n<p>Ctrl + G (then type line number)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"319\" valign=\"top\">\n<p>Select All<\/p>\n<\/td>\n<td width=\"319\" valign=\"top\">\n<p>Ctrl + A<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Not all of these commands are available as buttons on the tool bar. In fact, only the most common five commands appear on the tool bar. The remaining commands are available via the <b>Edit <\/b>menu (or you can use the keyboard shortcuts to avoid having to remove your hands from the keyboard to use the mouse). The five tool bar buttons are shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3386.hsg-2-7-12-5.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3386.hsg-2-7-12-5.png\" alt=\"Image of tool bar\" title=\"Image of tool bar\" \/><\/a><\/p>\n<p>BW, that is all there is to using the Windows PowerShell ISE to edit scripts and to set the execution policy. ISE Week will continue tomorrow when I will talk about more cool things.<\/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><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn about using the Windows PowerShell ISE to edit scripts, and to modify the script execution policy in this step-by-step blog. &nbsp;Hey, Scripting Guy! I have a problem. I was following your blog yesterday about &nbsp;typing long commands inside the Windows PowerShell ISE, and I saved my work because I did not want to [&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":[51,3,4,45,100],"class_list":["post-11221","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell","tag-windows-powershell-ise"],"acf":[],"blog_post_summary":"<p>Summary: Learn about using the Windows PowerShell ISE to edit scripts, and to modify the script execution policy in this step-by-step blog. &nbsp;Hey, Scripting Guy! I have a problem. I was following your blog yesterday about &nbsp;typing long commands inside the Windows PowerShell ISE, and I saved my work because I did not want to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/11221","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=11221"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/11221\/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=11221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=11221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=11221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}