{"id":17810,"date":"2008-12-29T07:23:40","date_gmt":"2008-12-29T15:23:40","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/powershell\/?p=17810"},"modified":"2019-06-07T07:25:00","modified_gmt":"2019-06-07T15:25:00","slug":"my-powershell_ise-profile","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/my-powershell_ise-profile\/","title":{"rendered":"My PowerShell_ISE Profile"},"content":{"rendered":"<p><P>[UDPATE&nbsp;&#8211; the original post&nbsp;had a script which did not work with CTP3 so I&#8217;ve replaced it with the correct version.&nbsp; Apologizes for the screw up. <BR>I&#8217;ve updated the attached file as well. &#8211; jps]&nbsp;<\/P>\n<P>I thought I would share my PowerShell_ISE profile with you.&nbsp; I haven&#8217;t done anything to clean this up or document it which I should do before sharing but I figured that it would be better to get some good examples out there and then I can clean it up later.<\/P>\n<P mce_keep=\"true\">&nbsp;<\/P>\n<P><FONT color=#0000ff size=2 face=Consolas># I&#8217;m doing a lot of work with Modules these days so I added a drive to make it easy to <BR># get to. <\/FONT><\/P>\n<P><FONT color=#0000ff size=2 face=Consolas>New-PsDrive -Name Mod -PSProvider FileSystem -Root (($env:PSMODULEPATH -split &#8220;;&#8221;)[0]) <BR>Set-Alias Open PowerShell_ise<\/FONT><\/P>\n<P><FONT color=#0000ff size=2 face=Consolas>&lt;# <BR>This function is now built-in to the editor so it is no longer needed.&nbsp; <BR>I&#8217;m keeping it here so you can see how it works.<BR>function GoTo-Line<BR>{<BR>&nbsp;&nbsp;&nbsp; $ed = $psise.CurrentOpenedFile.Editor<BR>&nbsp;&nbsp;&nbsp; [int]$l = read-host<BR>&nbsp;&nbsp;&nbsp; if ($l -le $ed.LineCount)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ed.SetCaretPosition($l,1) <BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp; {O<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ed.SetCaretPosition($ed.LineCount,1)<BR>&nbsp;&nbsp;&nbsp; }<BR>}<BR>#&gt;<BR>function Edit-Selected<BR>{<BR>&nbsp;&nbsp;&nbsp; $ed = $psise.CurrentOpenedFile.Editor<BR>&nbsp;&nbsp;&nbsp; PowerShell_ise $ed.SelectedText<BR>} <\/FONT><\/P>\n<P><FONT color=#0000ff size=2 face=Consolas>function global:Export-SessionFiles<BR>{<BR>&nbsp;&nbsp;&nbsp; $psise.CurrentOpenedRunspace.OpenedFiles |%{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!$_.isSaved)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $title = &#8220;Save File?&#8221;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $message = &#8220;Do you want to Save `n`t$($_.FullPath)`nbefore exporting?&#8221;<\/FONT><\/P>\n<P><FONT color=#0000ff size=2 face=Consolas>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $yes = New-Object System.Management.Automation.Host.ChoiceDescription &#8220;&amp;Yes&#8221;, `<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;Save $($_.FullPath).&#8221;<\/FONT><\/P>\n<P><FONT color=#0000ff size=2 face=Consolas>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $no = New-Object System.Management.Automation.Host.ChoiceDescription &#8220;&amp;No&#8221;, `<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;Export but do not save $($_.fullpath).&#8221;<\/FONT><\/P>\n<P><FONT color=#0000ff size=2 face=Consolas>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)<\/FONT><\/P>\n<P><FONT color=#0000ff size=2 face=Consolas>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (($host.ui.PromptForChoice($title, $message, $options, 0)) -eq 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $_.Save()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $psise.CurrentOpenedRunspace.Output.InsertText(&#8220;`nExporting $($_.FullPath)&#8221;)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $_.FullPath<BR>&nbsp;&nbsp;&nbsp; } &gt; ~\/ISE-SessionFiles.txt<BR>}<\/FONT><\/P>\n<P><FONT color=#0000ff size=2 face=Consolas>function Import-SessionFiles<BR>{<BR>&nbsp;&nbsp;&nbsp; cat ~\/ISE-SessionFiles.txt | %{ $psise.CurrentOpenedRunspace.OpenedFiles.add($_) }<BR>}<\/FONT><\/P>\n<P><FONT color=#0000ff size=2 face=Consolas>$null = $psISE.CustomMenu.Submenus.Add(&#8220;Edit Selected&#8221;, {Edit-Selected}, &#8216;Ctrl+E&#8217;)<BR>$null = $psISE.CustomMenu.Submenus.Add(&#8220;Export Session Files&#8221;, {Export-SessionFiles}, &#8216;Ctrl+SHIFT+E&#8217;)<BR>$null = $psISE.CustomMenu.Submenus.Add(&#8220;Import Session Files&#8221;, {Import-SessionFiles}, &#8216;Ctrl+SHIFT+I&#8217;)<BR><\/FONT><\/P>\n<P mce_keep=\"true\">&nbsp;<\/P>\n<P>Enjoy<\/P>\n<P>Jeffrey Snover [MSFT] <BR>Windows Management Partner Architect <BR>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp;&nbsp; <A href=\"http:\/\/blogs.msdn.com\/PowerShell\" mce_href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/A> <BR>Visit the Windows PowerShell ScriptCenter at:&nbsp; <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\" mce_href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/A><\/P><\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/MSDNBlogsFS\/prod.evol.blogs.msdn.com\/CommunityServer.Components.PostAttachments\/00\/09\/25\/62\/96\/Microsoft.PowerShellISE_Profile.ps1\" original-url=\"http:\/\/blogs.msdn.com\/cfs-file.ashx\/__key\/communityserver-components-postattachments\/00-09-25-62-96\/Microsoft.PowerShellISE_5F00_Profile.ps1\">Microsoft.PowerShellISE_Profile.ps1<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[UDPATE&nbsp;&#8211; the original post&nbsp;had a script which did not work with CTP3 so I&#8217;ve replaced it with the correct version.&nbsp; Apologizes for the screw up. I&#8217;ve updated the attached file as well. &#8211; jps]&nbsp; I thought I would share my PowerShell_ISE profile with you.&nbsp; I haven&#8217;t done anything to clean this up or document it [&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":[137,210,260],"class_list":["post-17810","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-ctp3","tag-jeffrey-snover","tag-powershell-ise"],"acf":[],"blog_post_summary":"<p>[UDPATE&nbsp;&#8211; the original post&nbsp;had a script which did not work with CTP3 so I&#8217;ve replaced it with the correct version.&nbsp; Apologizes for the screw up. I&#8217;ve updated the attached file as well. &#8211; jps]&nbsp; I thought I would share my PowerShell_ISE profile with you.&nbsp; I haven&#8217;t done anything to clean this up or document it [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/17810","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=17810"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/17810\/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=17810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=17810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=17810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}