{"id":1391,"date":"2014-11-19T16:04:00","date_gmt":"2014-11-19T16:04:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2014\/11\/19\/powershell-remote-script-debugging-in-the-ise\/"},"modified":"2019-02-18T12:38:47","modified_gmt":"2019-02-18T19:38:47","slug":"powershell-remote-script-debugging-in-the-ise","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/powershell-remote-script-debugging-in-the-ise\/","title":{"rendered":"PowerShell Remote Script Debugging in the ISE"},"content":{"rendered":"<p>This is the second of a series of blogs discussing the new PowerShell 5.0 script debugging features.&nbsp; These new features are available through the PowerShell 5.0 preview, which is part of the WMF (Windows Management Foundation) 5.0 preview that you can get from <a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2014\/11\/18\/windows-management-framework-5-0-preview-november-2014-is-now-available.aspx\">HERE<\/a>.<\/p>\n<p>In this blog I will discuss the new features that support remote script debugging in the PowerShell ISE (Integrated Script Environment).&nbsp; Remote script debugging support was added to PowerShell 4.0 but only for the PowerShell console and not the ISE.&nbsp; We have rectified this for PowerShell 5.0 and have also added the ability to open, edit and save remote script files.&nbsp; The PowerShell console does not provide for editing remote script files and so we felt this was an important feature for the ISE.&nbsp; In addition you can now also edit remote files in the ISE that have been opened for debugging.&nbsp; Thus you can perform full open\/edit\/run\/debug\/edit\/run iterations in the ISE on remote session files.&nbsp;<\/p>\n<p>You open a remote file for editing inside a PowerShell remote session from the ISE console pane using the <strong>PSEdit<\/strong> command.<\/p>\n<p><strong>PSEdit <\/strong>[-FileNames] &lt;string[]&gt; [CommonParameters]<\/p>\n<p>[RemoteMachine] PS C:\\&gt; <strong>PSEdit<\/strong> MyScript.ps1<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/30\/2018\/10\/3107.ISE2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/30\/2018\/10\/3107.ISE2.png\" alt=\"\" border=\"0\" \/><\/a><\/p>\n<p>I want to stress that this is <em>not<\/em> the same as opening a file using the ISE File Open Dialog.&nbsp; This dialog uses the Windows file system to navigate and open files, and you can even open remote files with the Windows network file system support.&nbsp; But the new PSEdit command support in remote sessions opens files through the <em>current remote session<\/em>. &nbsp;In other words it uses the same session connection your remote session uses and completely bypasses the network file system. &nbsp;It is also integrated with the ISE debugger so that remote files are automatically opened for debugging which are then available for editing.&nbsp; When the ISE opens a remote file for editing or debugging it simply copies the file from the remote machine to the local machine and stores it in a temporary local file.&nbsp; When you save changes to the file, the file is then copied from the local machine back to the remote machine.&nbsp; If you end the remote session (by running the Exit-PSSession Cmdlet) all remote files opened in the ISE are automatically closed since the remote connection supporting the file transfer no longer exists.&nbsp; We currently don&rsquo;t provide any way to save the remote file permanently onto the local machine but it is something we are considering.<\/p>\n<p>The PSEdit command actually already exists in the ISE when you are in a local session (ISE default mode) and it is a way to open local files from the ISE console command line.&nbsp;<br \/>This change simply extends this command to work in remote sessions too.<\/p>\n<p>To see how this works try doing the following (after installing the latest PowerShell 5.0 preview).<\/p>\n<ul>\n<li>Start PowerShell ISE<\/li>\n<li>Start a remote session by selecting the <em>File -&gt; New Remote PowerShell Tab&hellip; <\/em>menu item.<\/li>\n<li>If you have a second machine select that for the target of the remote session, but make sure that machine also has the latest PowerShell 5.0 preview installed.<\/li>\n<li>As an alternative and for experimentation purposes you can use &ldquo;localhost&rdquo; as the computer name in the New Remote PowerShell Tab dialog.&nbsp; This will create a remote connection back to your same machine.<\/li>\n<li>In the PowerShell console use the PSEdit command to open an existing remote file.<\/li>\n<\/ul>\n<p style=\"padding-left: 60px\">[paulhig-1]: PS C:\\&gt; PSEdit C:\\MyScripts\\MyScript.ps1<\/p>\n<ul>\n<li>Or alternatively create a new empty file and open that to create a new script file.<\/li>\n<\/ul>\n<p style=\"padding-left: 60px\">[paulhig-1]: PS C:\\&gt; New-Item C:\\MyScripts\\MyNewScript.ps1<\/p>\n<p style=\"padding-left: 60px\">[paulhig-1]: PS C:\\&gt; PSEdit C:\\MyScripts\\MyNewScript.ps1<\/p>\n<ul>\n<li>Your selected remote file is now open and displayed in the ISE.<\/li>\n<li>Set line breakpoints in the script file.<\/li>\n<li>Run the script.&nbsp; Let the script run to the breakpoint and step through the script.<\/li>\n<li>Stop the debugger.&nbsp; Edit the script.&nbsp; Save and run it again.<\/li>\n<\/ul>\n<p>&nbsp;<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/30\/2018\/10\/4645.ISE3.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/30\/2018\/10\/4645.ISE3.png\" alt=\"\" border=\"0\" \/><\/a><\/p>\n<p>That is really all there is to it.&nbsp; It is a fairly simple feature addition but makes creating, opening, editing, running, and debugging PowerShell script files on a remote machine a much better experience.<\/p>\n<p>Paul Higinbotham [MSFT]<\/p>\n<p>Windows PowerShell Development<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the second of a series of blogs discussing the new PowerShell 5.0 script debugging features.&nbsp; These new features are available through the PowerShell 5.0 preview, which is part of the WMF (Windows Management Foundation) 5.0 preview that you can get from HERE. In this blog I will discuss the new features that support [&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":[],"class_list":["post-1391","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>This is the second of a series of blogs discussing the new PowerShell 5.0 script debugging features.&nbsp; These new features are available through the PowerShell 5.0 preview, which is part of the WMF (Windows Management Foundation) 5.0 preview that you can get from HERE. In this blog I will discuss the new features that support [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/1391","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=1391"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/1391\/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=1391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=1391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=1391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}