{"id":8666,"date":"2021-10-29T12:50:19","date_gmt":"2021-10-29T16:50:19","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=8666"},"modified":"2021-10-29T12:50:23","modified_gmt":"2021-10-29T16:50:23","slug":"friday-fun-powershell-console-editing","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/","title":{"rendered":"Friday Fun: PowerShell Console Editing"},"content":{"rendered":"\n<p>The other day I read an interesting article on Adam Bertram's blog about <a href=\"https:\/\/adamtheautomator.com\/powershell-text-editor\/\" target=\"_blank\" rel=\"noreferrer noopener\">editing files with a text editor in PowerShell<\/a>. Naturally, the PowerShell wheels in my head began turning. While I was intrigued by some of the options in the article, I've in fact installed the Micro editor to play with, I realized I already had my favorite console text editor installed. The article mentioned installing the Nano editor for Windows. But I have a WSL installation of Ubuntu. I already have the nano editor.  To be fair, I installed Nano for Windows but it is just different enough from the Linux version to annoy me. Why not make it easier to use what I already have in my PowerShell console? Let's have some fun and maybe learn something new. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">WSL Commands<\/h2>\n\n\n\n<p>If you have a Linux distribution installed, you can run native Linux commands from your PowerShell prompt.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/wsl-commands.png\"><img loading=\"lazy\" decoding=\"async\" width=\"667\" height=\"329\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/wsl-commands.png\" alt=\"\" class=\"wp-image-8667\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/wsl-commands.png 667w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/wsl-commands-300x148.png 300w\" sizes=\"auto, (max-width: 667px) 100vw, 667px\" \/><\/a><\/figure>\n\n\n\n<p>Typically, these commands are running in a Linux shell but I'm getting the output in my PowerShell console. Regardless, I can easily launch the nano editor directly from my PowerShell prompt.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">wsl nano<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Converting Paths<\/h2>\n\n\n\n<p>But here's where it gets tricky. I want to be able to launch the nano editor and open a text file from Windows. In Linux, I can run a command like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">nano \/home\/jeff\/file.txt<\/code><\/pre>\n\n\n\n<p>If I try something like this from my PowerShell prompt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">wsl nano c:\\work\\fun.ps1<\/code><\/pre>\n\n\n\n<p>The nano editor will open but think I am creating a new file. That's because nano is really running in the Ubuntu distribution, not my PowerShell prompt. Luckily, all of my local drives are automatically mounted in WSL. If I  convert the path in my head, this will work.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">wsl nano \/mnt\/c\/work\/fun.ps1<\/code><\/pre>\n\n\n\n<p>Of course, I want things to be simple and easy so I'll need a function to convert a Windows path to the WSL mounted path. First, I should convert the Windows path to a true file system path. This will help convert paths like .\\file.txt or where I'm using a PSDrive like S:\\remote.ps1.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$cPath = Convert-Path -Path $Path<\/code><\/pre>\n\n\n\n<p>I'm then going to split this converted path into the parent directory and file name.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$file = Split-Path -Path $cpath -Leaf\n$dir = Split-Path -Path $cPath -Parent<\/code><\/pre>\n\n\n\n<p>Next, I want the path portion of the parent directory without the drive letter. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$folder = $dir.Substring(3)<\/code><\/pre>\n\n\n\n<p>I am doing all of this because I need to build the corresponding path in Linux using the mount point.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">\"\/mnt\/{0}\/{1}\/{2}\" -f $dir[0].tostring().ToLower(), $folder.replace(\"\\\", \"\/\"), $file<\/code><\/pre>\n\n\n\n<p>I'm building a new string using the first letter of the parent directory. Because Linux is case-sensitive I'm converting it to lowercase to match the path in Linux. The other accommodation I have to make is to switch all the \\ to \/.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/convertto-wslpath.png\"><img loading=\"lazy\" decoding=\"async\" width=\"434\" height=\"95\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/convertto-wslpath.png\" alt=\"\" class=\"wp-image-8668\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/convertto-wslpath.png 434w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/convertto-wslpath-300x66.png 300w\" sizes=\"auto, (max-width: 434px) 100vw, 434px\" \/><\/a><\/figure>\n\n\n\n<p>Now the nano command works as expected.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"658\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano-1024x658.png\" alt=\"\" class=\"wp-image-8669\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano-1024x658.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano-300x193.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano-768x493.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano-850x546.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano.png 1107w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Building a Tool Set<\/h2>\n\n\n\n<p>Of course, I also built a PowerShell function to launch nano, taking into account if I wanted to edit an existing file or create something new.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">[string]$cmd = \"wsl --exec nano\"\nif ($Path) {\n    $wslPath = ConvertTo-WSLPath -Path $Path\n    $cmd += \" $wslPath\"\n\n}\n#convert to a scriptblock\n$sb = [scriptblock]::Create($cmd)\nInvoke-Command -ScriptBlock $sb<\/code><\/pre>\n\n\n\n<p>This is the core of the function.<\/p>\n\n\n\n<p>The last pieces that I added were related to validation. My ConvertTo-WSLPath and Invoke-Nano functions are in a .ps1 file which I will have to dot source.  But the commands can't be used if there is no WSL installation<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$WslTest = ((wsl -l).split()).where({$_.length -gt 1}) -contains \"(Default)\"\nIf ( -Not $WslTest) {\n    Write-Warning \"These commands require a WSL installation\"\n    Return\n}<\/code><\/pre>\n\n\n\n<p>Figuring this out took way more effort than I imagined. You can run wsl -l to see installed installations. However, the encoding of the output isn't necessarily what you see in the console. My efforts to use -Match or Select-String kept failing. Eventually, I came up with this code to split the results of the wsl command into an array of strings with a length greater than 1. Then I can use -Contains looking for '(Default)'. If the string isn't found, I'll display a warning and then bail out of the script.<\/p>\n\n\n\n<p>I also wanted to verify that whoever is dot sourcing the script is running in Windows, either PowerShell 7 or Windows PowerShell. My functions are defined inside an If statement.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">if ($IsWindows -OR ($PSEdition -eq 'desktop')) {\n #define functions\n}\nElse {\n    Write-Warning \"These commands require a Windows platform\"\n}<\/code><\/pre>\n\n\n\n<p>If the PowerShell console is anything else, then another warning is displayed. Want to see the final result?<\/p>\n\n\n\n<pre title=\"Install-Nano.ps1\" class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\"># requires -version 5.1\n\n#launch the nono text editor from a WSL installation like Ubuntu\n# or install the Windows version https:\/\/sourceforge.net\/projects\/nano-for-windows\/\n# or https:\/\/sourceforge.net\/projects\/micro-for-windows\/\n# https:\/\/micro-editor.github.io\/\n\nif ($IsWindows -OR ($PSEdition -eq 'desktop')) {\n\n    #test if there is a default WSL installation\n    $WslTest = ((wsl -l).split()).where({$_.length -gt 1}) -contains \"(Default)\"\n    If ( -Not $WslTest) {\n        Write-Warning \"These commands require a WSL installation\"\n        Return\n    }\n\n    # a helper function to convert a Windows path to the WSL equivalent\n    Function ConvertTo-WSLPath {\n        [cmdletbinding()]\n        [outputtype(\"String\")]\n\n        Param(\n            [Parameter(Position = 0, Mandatory, HelpMessage = \"Enter a Windows file system path\")]\n            [ValidateNotNullorEmpty()]\n            [string]$Path\n        )\n\n        Write-Verbose \"[$($myinvocation.mycommand)] Starting $($myinvocation.mycommand)\"\n        Write-Verbose \"[$($myinvocation.mycommand)] Converting $Path to a filesystem path\"\n        $cPath = Convert-Path -Path $Path\n        Write-Verbose \"[$($myinvocation.mycommand)] Converted to $cpath\"\n\n        $file = Split-Path -Path $cpath -Leaf\n        $dir = Split-Path -Path $cPath -Parent\n        $folder = $dir.Substring(3)\n        \"\/mnt\/{0}\/{1}\/{2}\" -f $dir[0].tostring().ToLower(), $folder.replace(\"\\\", \"\/\"), $file\n\n        Write-Verbose \"[$($myinvocation.mycommand)] Ending $($myinvocation.mycommand)\"\n    }\n\n    #launch the nano editor from the WSL installation\n    Function Invoke-Nano {\n        [CmdletBinding()]\n        [outputtype(\"none\")]\n        [alias(\"nano\")]\n\n        Param(\n            [Parameter(Position = 0, HelpMessage = \"Specify a text file path.\")]\n            [ValidatenotNullorEmpty()]\n            [ValidateScript({ Test-Path $_ })]\n            [string]$Path\n        )\n        Write-Verbose \"[$($myinvocation.mycommand)] Starting $($myinvocation.mycommand)\"\n        [string]$cmd = \"wsl --exec nano\"\n        if ($Path) {\n            Write-Verbose \"[$($myinvocation.mycommand)] Convert $Path\"\n            $wslPath = ConvertTo-WSLPath -Path $Path\n            $cmd += \" $wslPath\"\n\n        }\n        Write-Verbose \"[$($myinvocation.mycommand)] Using command expression $cmd\"\n        #convert to a scriptblock\n        $sb = [scriptblock]::Create($cmd)\n\n        Write-Verbose \"[$($myinvocation.mycommand)] Launch nano from the WSL installation\"\n        Invoke-Command -ScriptBlock $sb\n        Write-Verbose \"[$($myinvocation.mycommand)] Ending $($myinvocation.mycommand)\"\n    }\n}\nElse {\n    Write-Warning \"These commands require a Windows platform\"\n}<\/code><\/pre>\n\n\n\n<p>I want to point out something new I'm trying with my Verbose statements.  I often have functions calling other functions. In each verbose statement, I'm including the command name. This makes it easier to track the flow.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano-verbose.png\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"200\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano-verbose.png\" alt=\"\" class=\"wp-image-8670\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano-verbose.png 900w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano-verbose-300x67.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano-verbose-768x171.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano-verbose-850x189.png 850w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/a><\/figure>\n\n\n\n<p>Now, I can quickly edit files directly from the PowerShell console.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"658\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano2-1024x658.png\" alt=\"\" class=\"wp-image-8671\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano2-1024x658.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano2-300x193.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano2-768x493.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano2-850x546.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/nano2.png 1107w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>And no, this doesn't replace the functionality I'd get from using VS Code or the PowerShell ISE. But sometimes I just want to make a quick edit or perhaps view source code. I'm partial to the nano editor, but you could use these concepts to launch vim or any other text editor you have installed in your WSL installation.<\/p>\n\n\n\n<p>Have fun.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The other day I read an interesting article on Adam Bertram&#8217;s blog about editing files with a text editor in PowerShell. Naturally, the PowerShell wheels in my head began turning. While I was intrigued by some of the options in the article, I&#8217;ve in fact installed the Micro editor to play with, I realized I&#8230;<\/p>\n","protected":false},"author":1,"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,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New on the blog -> Friday Fun: #PowerShell Console Editing","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8],"tags":[568,224,534,540,660],"class_list":["post-8666","post","type-post","status-publish","format-standard","hentry","category-scripting","tag-friday-fun","tag-function","tag-powershell","tag-scripting","tag-wsl"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Friday Fun: PowerShell Console Editing &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"I need a simple text editor I can use directly in my PowerShell session. Luckily, I have one in my WSL installation. Here&#039;s how I use it.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Friday Fun: PowerShell Console Editing &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I need a simple text editor I can use directly in my PowerShell session. Luckily, I have one in my WSL installation. Here&#039;s how I use it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-29T16:50:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-10-29T16:50:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/wsl-commands.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Friday Fun: PowerShell Console Editing\",\"datePublished\":\"2021-10-29T16:50:19+00:00\",\"dateModified\":\"2021-10-29T16:50:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/\"},\"wordCount\":775,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/wsl-commands.png\",\"keywords\":[\"Friday Fun\",\"Function\",\"PowerShell\",\"Scripting\",\"WSL\"],\"articleSection\":[\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/\",\"name\":\"Friday Fun: PowerShell Console Editing &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/wsl-commands.png\",\"datePublished\":\"2021-10-29T16:50:19+00:00\",\"dateModified\":\"2021-10-29T16:50:23+00:00\",\"description\":\"I need a simple text editor I can use directly in my PowerShell session. Luckily, I have one in my WSL installation. Here's how I use it.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/wsl-commands.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/wsl-commands.png\",\"width\":667,\"height\":329},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/8666\\\/friday-fun-powershell-console-editing\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Scripting\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/scripting\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Friday Fun: PowerShell Console Editing\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Friday Fun: PowerShell Console Editing &#8226; The Lonely Administrator","description":"I need a simple text editor I can use directly in my PowerShell session. Luckily, I have one in my WSL installation. Here's how I use it.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/","og_locale":"en_US","og_type":"article","og_title":"Friday Fun: PowerShell Console Editing &#8226; The Lonely Administrator","og_description":"I need a simple text editor I can use directly in my PowerShell session. Luckily, I have one in my WSL installation. Here's how I use it.","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/","og_site_name":"The Lonely Administrator","article_published_time":"2021-10-29T16:50:19+00:00","article_modified_time":"2021-10-29T16:50:23+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/wsl-commands.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Friday Fun: PowerShell Console Editing","datePublished":"2021-10-29T16:50:19+00:00","dateModified":"2021-10-29T16:50:23+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/"},"wordCount":775,"commentCount":2,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/wsl-commands.png","keywords":["Friday Fun","Function","PowerShell","Scripting","WSL"],"articleSection":["Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/","name":"Friday Fun: PowerShell Console Editing &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/wsl-commands.png","datePublished":"2021-10-29T16:50:19+00:00","dateModified":"2021-10-29T16:50:23+00:00","description":"I need a simple text editor I can use directly in my PowerShell session. Luckily, I have one in my WSL installation. Here's how I use it.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/wsl-commands.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/wsl-commands.png","width":667,"height":329},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/8666\/friday-fun-powershell-console-editing\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Scripting","item":"https:\/\/jdhitsolutions.com\/blog\/category\/scripting\/"},{"@type":"ListItem","position":2,"name":"Friday Fun: PowerShell Console Editing"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":8684,"url":"https:\/\/jdhitsolutions.com\/blog\/wpf\/8684\/creating-a-powershell-clock\/","url_meta":{"origin":8666,"position":0},"title":"Creating a PowerShell Clock","author":"Jeffery Hicks","date":"November 9, 2021","format":false,"excerpt":"I've published a new project to the PowerShell Gallery. This is something that I needed, and maybe you do as well. Even though I have the typical clock running in the Windows taskbar, I have an ultrawide monitor so it isn't always easy to read. I had been running the\u2026","rel":"","context":"In &quot;Scripting&quot;","block_context":{"text":"Scripting","link":"https:\/\/jdhitsolutions.com\/blog\/category\/scripting\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/11\/sample-2.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":101,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/101\/updated-powershell-help-utility\/","url_meta":{"origin":8666,"position":1},"title":"Updated PowerShell Help Utility","author":"Jeffery Hicks","date":"February 19, 2007","format":false,"excerpt":"SAPIEN Technologies has released a new version of their free PowerShellHelp tool. This tool gets all the help information from your PowerShell installation and presents it in a nice GUI that now looks like Office 2007. The screen shot doesn't really do it justice, but you get the idea.Not only\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":383,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/383\/primalforms-2009-script-editor\/","url_meta":{"origin":8666,"position":2},"title":"PrimalForms 2009 Script Editor","author":"Jeffery Hicks","date":"September 22, 2009","format":false,"excerpt":"SAPIEN\u2019s Primal Forms 2009 now has an integrated script editor that you can use as a standalone editor for PowerShell scripts. The app has integrated help, popup command help, a PowerShell browser, a .NET object browser. As you can see in the screen shot I\u2019ve started a very basic PowerShell\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"primalforms2009-script","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/primalforms2009script_thumb.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3455,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3455\/friday-fun-color-my-web\/","url_meta":{"origin":8666,"position":3},"title":"Friday Fun Color My Web","author":"Jeffery Hicks","date":"September 20, 2013","format":false,"excerpt":"Awhile ago I posted an article demonstrating using Invoke-Webrequest which is part of PowerShell 3.0. I used the page at Manning.com to display the Print and MEAP bestsellers. By the way, thanks to all of you who keep making PowerShell books popular. My original script simply wrote the results to\u2026","rel":"","context":"In &quot;Books&quot;","block_context":{"text":"Books","link":"https:\/\/jdhitsolutions.com\/blog\/category\/books\/"},"img":{"alt_text":"get-manningbestseller1","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/09\/get-manningbestseller1-1024x606.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/09\/get-manningbestseller1-1024x606.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/09\/get-manningbestseller1-1024x606.png?resize=525%2C300 1.5x"},"classes":[]},{"id":153,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/153\/primalforms-now-available\/","url_meta":{"origin":8666,"position":4},"title":"PrimalForms now Available","author":"Jeffery Hicks","date":"November 3, 2008","format":false,"excerpt":"Even though PowerShell is by design a console based management tool, there are instances where you would like to use a GUI. PowerShell can use the Windows forms classes from the .NET Framework. However in the past creating anything other than the simplest of forms was very tedious and time\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5293,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5293\/are-you-my-nano\/","url_meta":{"origin":8666,"position":5},"title":"Are You My Nano?","author":"Jeffery Hicks","date":"October 21, 2016","format":false,"excerpt":"I've been diving a bit deeper into the Nano waters now that Windows Server 2016 is out the door. As I deployed a few servers I realized there was a potential long-term management issue. During the technical preview, Nano installations were recognized by their Tuva designation. But now, a Nano\u2026","rel":"","context":"In &quot;Nano Server&quot;","block_context":{"text":"Nano Server","link":"https:\/\/jdhitsolutions.com\/blog\/category\/nano-server\/"},"img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/10\/image_thumb-4.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/10\/image_thumb-4.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/10\/image_thumb-4.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=8666"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8666\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}