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’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 proceeding, maybe you would like to take a look on the blog where I explained how to keep your powershell scripts in cloudshell. It’s also interesting to discover how to map the cloudshell file share to your local machine and edit the scripts using powershell ISE.
Let’s discover how to achieve this magic.
First, you may would like to confirm Powershell version in Cloudshell. You can do so using $PSVversionTable
It’s time to install the new version of Powershell. You can do this using a single statement.
How does it work
The basic statement for the installation is the following:
IEX is a shortcut for the Invoke-Expression cmdlet. You can check more about Invoke-Expression here
IRM is a shortcut for the Invoke-RestMethod. Used with a URL, t will download the URL. You can check more about Invoke-RestMethod
In summary, this statement is downloading the powershell script on https://aka.ms/install-powershell.ps1 and executing it. This script will be the responsible for the powershell installation.
This script has some parameters, the most important ones are:
-Preview : If you use this parameter, you will be installing the latest preview version of Powershell. Otherwise you will install the latest GA version
-Destination: This is very important on our scenario, because you need to install Powershell inside the CloudDrive folder, otherwise you will lose it and have to install it multiple times.
The final statement will be like this one:
Take care about how you specify the path, it depends on your local folder
Using the New Version
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:
I like the color code used by PowerShell 7.3. You may would like to know what’s new in Powershell 7.3
Blog by blog we are discovering the full power of CloudShell and how it can help us on our daily tasks