{"id":400,"date":"2019-10-23T20:01:40","date_gmt":"2019-10-24T02:01:40","guid":{"rendered":"http:\/\/draith.com\/?p=400"},"modified":"2019-12-10T02:29:05","modified_gmt":"2019-12-10T02:29:05","slug":"add-multiple-powershell-versions-to-vscode","status":"publish","type":"post","link":"https:\/\/draith.azurewebsites.net\/?p=400","title":{"rendered":"Add multiple powershell versions to Vscode"},"content":{"rendered":"\n<h1>Here is the quick and dirty way to add multiple PowerShell versions to VSCode, and switch between them quickly.<\/h1>\n\n\n\n<p>It&#8217;s often times advantageous to quickly switch between multiple versions of a programming language when coding to ensure that your code works on multiple platforms.&nbsp; For me, that is switching between Windows PowerShell and multiple versions of Microsoft PowerShell (PowerShell Core).&nbsp; He&#8217;s how to easily do it in VSCode.<\/p>\n<p>First, I am going to assume you have the PowerShell extension already installed in VSCode.&nbsp; If not, hit F1 (Ctrl-Shift-P) to open the command palette, and type this<\/p>\n<p>&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-\">ext install powershell<\/code><\/pre>\n\n\n\n<p>Now, let&#8217;s get some different PowerShell versions.&nbsp; <a href=\"https:\/\/github.com\/PowerShell\/PowerShell\/releases\/tag\/v7.0.0-preview.5\">This is the link to PowerShell 7 preview 5<\/a>.&nbsp; Down that and extract it to any directory you want.&nbsp; In this example I will also be using the latest stable version &#8211; 6.2.3.&nbsp; In this example I have downloaded them both to the c:\\pwsh directory.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1108\" height=\"282\" src=\"https:\/\/i0.wp.com\/draith.com\/wp-content\/uploads\/2019\/10\/folder.png?fit=474%2C121\" alt=\"\" class=\"wp-image-401\" srcset=\"\/wp-content\/uploads\/2019\/10\/folder.png 1108w, \/wp-content\/uploads\/2019\/10\/folder-300x76.png 300w, \/wp-content\/uploads\/2019\/10\/folder-1024x261.png 1024w, \/wp-content\/uploads\/2019\/10\/folder-768x195.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure><\/div>\n\n\n\n<p>Open VSCode, and create a new file.&nbsp; Save the file with a .ps1 extension.&nbsp; Notice how the terminal automatically starts PowerShell, and that the little green number in the lower right says 5.1?&nbsp; That&#8217;s because VSCode is smart enough to look in common locations for PowerShell versions, and will add those automatically to your session options.&nbsp; Since we are putting the version in a non-typical location, we have to edit our settings.json.&nbsp; The easiest way to do it is this is to hit F1 (Ctrl-Shift-P), and type &#8216;language&#8217;.&nbsp; Select &#8220;Configure Language Specific Settings&#8221;<\/p>\n<p>&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1387\" height=\"352\" src=\"https:\/\/i1.wp.com\/draith.com\/wp-content\/uploads\/2019\/10\/settings.png?fit=474%2C120\" alt=\"\" class=\"wp-image-403\" srcset=\"\/wp-content\/uploads\/2019\/10\/settings.png 1387w, \/wp-content\/uploads\/2019\/10\/settings-300x76.png 300w, \/wp-content\/uploads\/2019\/10\/settings-1024x260.png 1024w, \/wp-content\/uploads\/2019\/10\/settings-768x195.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure><\/div>\n\n\n\n<p>You will open the settings.json for your user and language.&nbsp; If you haven&#8217;t done much with VSCode, it probably looks something like this:<\/p>\n<p>&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-json\">{\n    \"workbench.iconTheme\": \"vscode-icons\",\n    \"team.showWelcomeMessage\": false,\n    \"markdown.extension.toc.githubCompatibility\": true,\n    \"git.enableSmartCommit\": true,\n    \"git.autofetch\": true,\n    \"[powershell]\": {}\n} <\/code><\/pre>\n\n\n\n<p>To add our new versions, we need to add just a bit to this file.&nbsp; We are going to add powershell.powerShellAdditionalExePaths settings &#8211; in our case 2 of them.&nbsp; The important parts are to make sure you are escaping the &#8220;\\&#8221; slashes with another slash, and just follow normal JSON formatting requirements.&nbsp; Continuing with my example, my settings.json looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-json\">{\n    \"workbench.iconTheme\": \"vscode-icons\",\n    \"team.showWelcomeMessage\": false,\n    \"markdown.extension.toc.githubCompatibility\": true,\n    \"git.enableSmartCommit\": true,\n    \"git.autofetch\": true,\n    \"[powershell]\": {},\n    \n    \"powershell.powerShellAdditionalExePaths\": [\n        {\n            \"exePath\": \"C:\\\\pwsh\\\\7.p5\\\\pwsh.exe\",\n            \"versionName\": \"PowerShell Core 7p5\"\n        },\n        {\n            \"exePath\": \"C:\\\\pwsh\\\\6.2.3\\\\pwsh.exe\",\n            \"versionName\": \"PowerShell Core 6.2.3\"\n        }        \n    ],\n    \"powershell.powerShellDefaultVersion\": \"PowerShell Core 7p5\",\n    \"powershell.powerShellExePath\": \"C:\\\\pwsh\\\\7.p5\\\\pwsh.exe\"\n} <\/code><\/pre>\n\n\n\n<p>Save the settings file, and if you have an open terminal, either exit it, or crash\/reload.&nbsp; This will force VSCode to reload the settings file.&nbsp; If you have done it correctly, if you click on the little green version number in the lower right, you should see something like this:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1451\" height=\"620\" src=\"https:\/\/i2.wp.com\/draith.com\/wp-content\/uploads\/2019\/10\/versuibs.png?fit=474%2C203\" alt=\"\" class=\"wp-image-404\" srcset=\"\/wp-content\/uploads\/2019\/10\/versuibs.png 1451w, \/wp-content\/uploads\/2019\/10\/versuibs-300x128.png 300w, \/wp-content\/uploads\/2019\/10\/versuibs-1024x438.png 1024w, \/wp-content\/uploads\/2019\/10\/versuibs-768x328.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure><\/div>\n\n\n\n<p>Switch between them, and verify you see the various version with $PSVersionTable<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1462\" height=\"1049\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2019\/10\/6.2.png\" alt=\"\" class=\"wp-image-425\" srcset=\"\/wp-content\/uploads\/2019\/10\/6.2.png 1462w, \/wp-content\/uploads\/2019\/10\/6.2-300x215.png 300w, \/wp-content\/uploads\/2019\/10\/6.2-1024x735.png 1024w, \/wp-content\/uploads\/2019\/10\/6.2-768x551.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1468\" height=\"1052\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2019\/10\/5.png\" alt=\"\" class=\"wp-image-424\" srcset=\"\/wp-content\/uploads\/2019\/10\/5.png 1468w, \/wp-content\/uploads\/2019\/10\/5-300x215.png 300w, \/wp-content\/uploads\/2019\/10\/5-1024x734.png 1024w, \/wp-content\/uploads\/2019\/10\/5-768x550.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1461\" height=\"1051\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2019\/10\/7p5.png\" alt=\"\" class=\"wp-image-435\" srcset=\"\/wp-content\/uploads\/2019\/10\/7p5.png 1461w, \/wp-content\/uploads\/2019\/10\/7p5-300x216.png 300w, \/wp-content\/uploads\/2019\/10\/7p5-1024x737.png 1024w, \/wp-content\/uploads\/2019\/10\/7p5-768x552.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[16,25],"class_list":["post-400","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-powershell","tag-vscode"],"_links":{"self":[{"href":"https:\/\/draith.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/posts\/400","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/draith.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/draith.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/draith.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/draith.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=400"}],"version-history":[{"count":1,"href":"https:\/\/draith.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/posts\/400\/revisions"}],"predecessor-version":[{"id":499,"href":"https:\/\/draith.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/posts\/400\/revisions\/499"}],"wp:attachment":[{"href":"https:\/\/draith.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/draith.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/draith.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}