{"id":11266,"date":"2016-02-24T06:00:00","date_gmt":"2016-02-24T14:00:00","guid":{"rendered":"https:\/\/www.sapien.com\/blog\/?p=11266"},"modified":"2016-02-18T08:53:37","modified_gmt":"2016-02-18T16:53:37","slug":"is-there-a-psedit-for-powershell-studio","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2016\/02\/24\/is-there-a-psedit-for-powershell-studio\/","title":{"rendered":"Is there a PSEdit for PowerShell Studio?"},"content":{"rendered":"<p>My friend, <a href=\"https:\/\/twitter.com\/driberif\">Thom Schumacher<\/a>, who has been leading the <a href=\"https:\/\/twitter.com\/driberif\">Arizona PowerShell User Group<\/a> for the past few months, is getting to know PowerShell Studio. Like many of us, he came to PowerShell Studio from PowerShell ISE, so he looks for the &#8220;ISE way&#8221; to do things in PowerShell Studio.<\/p>\n<p><i>&#8220;How do I use PSEdit in PowerShell Studio?,&#8221;<\/i> Thom asked on Twitter. Here&#8217;s my answer.<\/p>\n<h1>Um, you don&#8217;t need it<\/h1>\n<p>Being very literal, you don&#8217;t need the PSEdit function in PowerShell Studio.<\/p>\n<p>The PSEdit function, which is defined in and works only in PowerShell ISE (not in the ISE module), opens a script that you specify in a new PowerShell Tab, that is, a new runspace.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/03\/Screenshot-2016-02-16-09.51.29.png\" rel=\"attachment wp-att-11268\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-11268\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/03\/Screenshot-2016-02-16-09.51.29.png\" alt=\"Screenshot 2016-02-16 09.51.29\" width=\"617\" height=\"343\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2016\/03\/Screenshot-2016-02-16-09.51.29.png 710w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2016\/03\/Screenshot-2016-02-16-09.51.29-300x167.png 300w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/a><\/p>\n<p>In ISE, you need to create a new runspace because, by default, everything that you run in ISE runs in the same runspace in its console. That&#8217;s obviously not the best test environment. A new runspace is an improvement, even though the new runspace still includes your personal PowerShell profiles and anything that they import or auto-load.<\/p>\n<p>As a best practice test environment, by default, <b>PowerShell Studio<\/b> runs every script in a new runspace every time. It not only creates a new runspace for every script. It creates a new runspace each time you use <b>Run<\/b>, <b>Run Selection<\/b>, or <b>Debug<\/b>, even if you run them repeatedly on the same script. You always get a new runspace. And, that runspace <i>never<\/i> includes PowerShell\u00a0profiles, so you don&#8217;t need to hide, move, or disable them.<\/p>\n<p>If you need a persistent runspace to share content, like variables, use the PowerShell Studio Console Pane. Run the script from the console or use the <b>Run in Console<\/b> or <b>Run Selection in Console<\/b> commands. Commands that run in the same Debug session also share a persistent runspace.<\/p>\n<p>&nbsp;<\/p>\n<h1>A PSEdit to Open a Script in PowerShell Studio<\/h1>\n<p>But, that&#8217;s probably too literal. Many people who use the PSEdit function aren&#8217;t even worried about a runspace. They just want a console command that opens a new script in their favorite editor.<\/p>\n<p>To open any script (.ps1), module (,psm1)\u00a0in\u00a0PowerShell Studio, use the\u00a0<a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113345\">Invoke-Item<\/a> cmdlet or its alias, <b>ii<\/b>.<\/p>\n<p>For example, this command opens the Get-CmdletAttributes.ps1 script in PowerShell Studio.<\/p>\n<pre lang=\"PowerShell\">ii C:\\Scripts\\Get-CmdletAttributes.ps1<\/pre>\n<p>You can use Invoke-Item in any PowerShell console, including, but not limited to, the PowerShell console in PowerShell Studio.<\/p>\n<p>The Invoke-Item cmdlet works because it opens the file in the program that is associated with that file type. When you install PowerShell Studio, the installer sets the file association for you.<\/p>\n<h1>A PSEdit to Open PowerShell Studio<\/h1>\n<p>When people ask for a &#8220;PSEdit&#8221; equivalent, sometimes they just want a console command to open PowerShell Studio.<\/p>\n<p>My CurrentUserAllHosts PowerShell profile includes this function. I named it &#8220;SPS&#8221; for &#8220;SAPIEN PowerShell Studio.&#8221; It works anywhere in PowerShell. It&#8217;s not limited to PowerShell Studio.<\/p>\n<p>When I want to open PowerShell Studio from any console (except the one in PowerShell Studio, of course), I type <strong>sps<\/strong>.<\/p>\n<pre lang=\"PowerShell\">function sps\r\n{\r\n    $keyPath = 'HKLM:\\Software\\Sapien Technologies, Inc.\\PowerShell Studio*'\r\n    \r\n    if ($key = (dir $keyPath | Sort-Object -Descending | Select-Object -First 1) -replace 'HKEY_LOCAL_MACHINE', 'HKLM:' )\r\n    {\r\n       if ($path = Get-ItemProperty -Path $key -Name Path)\r\n       {\r\n           Start-Process $path.Path\r\n       }\r\n       else\r\n       {\r\n           Write-Error \"Found PowerShell Studio. Cannot find path in $key.\"\r\n       }\r\n    }\r\n    else\r\n    {\r\n        Write-Error \"Cannot find PowerShell Studio on this computer.\"\r\n    }\r\n}<\/pre>\n<p>So, there you have it. If you&#8217;ve just started using PowerShell Studio, and you need an equivalent for your favorite command in your previous tool, post your request on our <a href=\"http:\/\/www.sapien.com\/forums\/viewforum.php?f=12\" target=\"_blank\">PowerShell Studio forum<\/a>.<\/p>\n<p><i>June Blender is a technology evangelist at SAPIEN Technologies, Inc. and a Windows PowerShell MVP. You can reach her at <\/i><a href=\"mailto:juneb@sapien.com\"><em>juneb@sapien.com<\/em><\/a><em> or follow her on Twitter at <\/em><a href=\"https:\/\/twitter.com\/juneb_get_help\"><em>@juneb_get_help<\/em><\/a><em>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>My friend, Thom Schumacher, who has been leading the Arizona PowerShell User Group for the past few months, is getting to know PowerShell Studio. Like many of us, he came to PowerShell Studio from PowerShell ISE, so he looks for the &#8220;ISE way&#8221; to do things in PowerShell Studio. &#8220;How do I use PSEdit in [&hellip;]<\/p>\n","protected":false},"author":31,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[932,703,303,25],"tags":[934,28,752,1016,1057,997],"class_list":["post-11266","post","type-post","status-publish","format-standard","hentry","category-beginners","category-powershell-studio","category-tip","category-windows-powershell","tag-juneb","tag-powershell","tag-powershell-editor","tag-powershell-studio","tag-psedit","tag-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/11266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=11266"}],"version-history":[{"count":9,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/11266\/revisions"}],"predecessor-version":[{"id":11277,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/11266\/revisions\/11277"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=11266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=11266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=11266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}