{"id":93689,"date":"2022-04-04T17:00:08","date_gmt":"2022-04-04T17:00:08","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=93689"},"modified":"2022-04-02T19:21:57","modified_gmt":"2022-04-02T19:21:57","slug":"updating-powershell-version-in-azure-cloudshell","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/updating-powershell-version-in-azure-cloudshell\/","title":{"rendered":"Updating Powershell version in Azure CloudShell"},"content":{"rendered":"<p><strong>Azure Cloudshell<\/strong> uses <strong>PowerShell 7.2.1<\/strong>. However, <strong>Powershell 7.2.2<\/strong> is already available and we have also a <strong>PowerShell<\/strong> version 7.3.0 in preview.<\/p>\n<p>Wouldn&#8217;t it be nice if you could update the powershell version in cloudshell, instead of waiting for Microsoft? This would allow you to run scripts using the new features of the updated versions.<\/p>\n<p>Before proceeding, maybe you would like to take a look on the blog where I explained <a href=\"https:\/\/www.red-gate.com\/simple-talk\/blogs\/start-stopping-virtual-machines-resource-group\/\">how to keep your powershell scripts in cloudshell<\/a>. It&#8217;s also interesting to discover how to <a href=\"https:\/\/www.red-gate.com\/simple-talk\/blogs\/azure-storage-mapping-file-shares-and-powershell-drives\/\">map the cloudshell file share to your local machine<\/a> and edit the scripts using powershell ISE.<\/p>\n<p>Let&#8217;s discover how to achieve this magic.<\/p>\n<p>First, you may would like to confirm <strong>Powershell<\/strong> version in <strong>Cloudshell<\/strong>. You can do so using <strong>$PSVversionTable<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-93695\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/04\/UpdateCshell01.png\" alt=\"\" width=\"1076\" height=\"307\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>It&#8217;s time to install the new version of <strong>Powershell<\/strong>. You can do this using a single statement.<\/p>\n<h2>How does it work<\/h2>\n<p>The basic statement for the installation is the following:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em\">\n<pre style=\"margin: 0;line-height: 125%\" class=\"crayon:false\">iex <span style=\"background-color: #fff0f0\">\"&amp; { <\/span><span style=\"background-color: #eeeeee\">$(irm https:\/\/aka.ms\/install-powershell.ps1)<\/span><span style=\"background-color: #fff0f0\"> }\"<\/span>\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>IEX<\/strong> is a shortcut for the <strong>Invoke-Expression<\/strong> cmdlet. You can <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/microsoft.powershell.utility\/invoke-expression?view=powershell-7.2\">check more about Invoke-Expression here<\/a><\/p>\n<p><strong>IRM<\/strong> is a shortcut for the <strong>Invoke-RestMethod<\/strong>. Used with a URL, t will download the URL. You can check <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/microsoft.powershell.utility\/invoke-restmethod?view=powershell-7.2\">more about Invoke-RestMethod<\/a><\/p>\n<p>In summary, this statement is downloading the powershell script on\u00a0https:\/\/aka.ms\/install-powershell.ps1 and executing it. This script will be the responsible for the powershell installation.<\/p>\n<p>This script has some parameters, the most important ones are:<\/p>\n<p><strong>-Preview :<\/strong> If you use this parameter, you will be installing the latest preview version of Powershell. Otherwise you will install the latest GA version<\/p>\n<p><strong>-Destination:<\/strong> This is very important on our scenario, because you need to install Powershell inside the <em>CloudDrive<\/em> folder, otherwise you will lose it and have to install it multiple times.<\/p>\n<p>The final statement will be like this one:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em\">\n<pre style=\"margin: 0;line-height: 125%\" class=\"crayon:false\">iex <span style=\"background-color: #fff0f0\">\"&amp; { <\/span><span style=\"background-color: #eeeeee\">$(irm https:\/\/aka.ms\/install-powershell.ps1)<\/span><span style=\"background-color: #fff0f0\"> } -Preview -Destination .\\clouddrive\\.Powershell\"<\/span>\r\n<\/pre>\n<\/div>\n<p>Take care about how you specify the path, it depends on your local folder<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-93696\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/04\/UpdateCShell02.png\" alt=\"\" width=\"1280\" height=\"148\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-93697\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/04\/UpdateCShell03.png\" alt=\"\" width=\"1280\" height=\"96\" \/><\/p>\n<h2>Using the New Version<\/h2>\n<p>The only bad news is that every time you start you start cloudshell you need to run the new powershell version. You need a single statement for this:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em\">\n<pre style=\"margin: 0;line-height: 125%\">.\\clouddrive\\.powershell\\pwsh\r\n<\/pre>\n<\/div>\n<p>I like the color code used by <strong>PowerShell 7.3<\/strong>. You may would like to know <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/scripting\/whats-new\/what-s-new-in-powershell-73\">what&#8217;s new in Powershell 7.3<\/a><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-93698\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/04\/UpdateCShell04.png\" alt=\"\" width=\"1213\" height=\"716\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>Summay<\/h2>\n<p>Blog by blog we are discovering the full power of <strong>CloudShell<\/strong> and how it can help us on our daily tasks<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Azure Cloudshell uses PowerShell 7.2.1. However, Powershell 7.2.2 is already available and we have also a PowerShell version 7.3.0 in preview. Wouldn&#8217;t it be nice if you could update the powershell version in cloudshell, instead of waiting for Microsoft? This would allow you to run scripts using the new features of the updated versions. Before&#8230;&hellip;<\/p>\n","protected":false},"author":50808,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[5364,145945,145936,4635],"coauthors":[6810],"class_list":["post-93689","post","type-post","status-publish","format-standard","hentry","category-blogs","tag-azure","tag-azure-portal","tag-cloudshell","tag-powershell"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/93689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/50808"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=93689"}],"version-history":[{"count":7,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/93689\/revisions"}],"predecessor-version":[{"id":105215,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/93689\/revisions\/105215"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=93689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=93689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=93689"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=93689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}