Getting Productive With Microsoft Azure Cloud Shell


Editor's note: The following post was written by Cloud and Datacenter Management MVP Timothy Warner as part of our Technical Tuesday series. Daron Yondem of the MVP Award Blog Technical Committee served as the technical reviewer for this piece.

Under ordinary circumstances, in order to get command-line access to your Microsoft Azure subscriptions, you would need to perform one of the following tasks:

  • Install Python and the Azure Command-Line Interface (CLI) v2.0
  • Install the Azure PowerShell modules
  • Install an Azure software development kit (SDK)

However, you and I both know we live under extraordinary circumstances in the Azure public cloud. Today I will teach you how to use the Azure Cloud Shell, a browser-based command shell that you should get familiar with sooner rather than later.

The value proposition

Azure Cloud Shell gives you command-line access to Azure directly from your web browser, all with no (thank you, Mark Minasi) "muss, fuss, or greasy aftertaste." You don't have to install any bits - the shell is right there, and you're already logged in and ready to rock.

In Azure Cloud Shell you can perform ad-hoc administration, troubleshooting, and even Azure Resource Manager (ARM) template deployment, all from a convenient command prompt. Of course, this means that you have to have proficiency with Azure PowerShell and Azure CLI. Here are a couple documentation links to get you started on your learning curve:

Getting started

Start a Cloud Shell by clicking the Cloud Shell button in the Azure portal. At first launch you'll see the Welcome to Azure Cloud shell dialog box.

Figure 1. Starting Azure Cloud Shell for the first time.

The first question asks whether you want to start with the Azure CLI v2.0 (Linux bash environment) or Azure PowerShell (cmd environment). Don't worry - you can always change your mind later.

As shown in Figure 2, the second question you're asked is how you want to persist your user data. Specifically, Azure Cloud Shell stores data in an Azure File Service file share.

Figure 2. Setting up Azure Cloud Shell persistent storage.

NOTE: If you remove your file share or the entire storage account, you will be prompted to create another one the next time you start Azure Cloud Shell. The shell will not run without a persistent file share. Of course, you will lose any cloud drive contents that you do not have backed up elsewhere.

You can interact with your cloud drive through the Azure portal, or with Azure PowerShell, or Azure CLI v2.0, inside or outside of Azure Cloud Shell. I show you the Azure portal interface in Figure 3.

Figure 3. You can store assets in your cloud drive.

Now let's turn our attention to navigating Azure Cloud Shell, starting with Azure PowerShell.

Azure PowerShell in Azure Cloud Shell

Take a look at Figure 4, in which I annotate the Azure Cloud Shell controls. I then describe it below:

Figure 4. The Azure Cloud Shell interface.

A: Choose between the Azure PowerShell and Azure CLI v2.0 environments (a shell restart is required)

B: Restart Azure Cloud Shell

C: Documentation links

D: Adjust text size or submit feedback to the Azure Cloud Shell development team

E: Click and drag to vertically resize the Azure Cloud Shell window

F: Minimize hides the Cloud Shell (click the Azure Cloud Shell icon to reinstate the session). Close quits the session

Honestly, I was surprised to see that Azure Cloud Shell runs Windows PowerShell v5.1 Desktop edition and not Core edition:

PS Azure:\> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.14393.1480
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.1480
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

The PowerShell development team told me that it is on their roadmap to use PowerShell Core in Azure Cloud Shell eventually. This seems like a good idea to me for performance reasons.

Do you see the PS Azure:\> prompt? Azure Cloud Shell mounts your associated Azure subscriptions as a PS provider drive. This means you can browse your Azure resources by using the typical PowerShell commands and aliases, as shown in Figure 5.

Figure 5. Navigating the Azure drive.

Of course, any of your favorite Azure PowerShell pipelines work just fine in Azure Cloud Console. Rather than make this a demo of Azure PowerShell (here's a nice quickstart from the Azure documentation), I want to focus on Azure Cloud Shell-specific features that may be of interest.

Take the cloud drive, for example. How can you run a PowerShell script you stored in the cloud drive file share? Well, as it happens, the PowerShell environment maps the cloud drive to drive Y:, which of course is exposed to you via the PowerShell provider system.

Check out my demo in Figure 6.

Figure 6. Running a script from my cloud drive.

Next, let's move over to the Linux cross-platform world in Azure Cloud Shell.

Azure CLI v2.0 in Azure Cloud Shell

Open the Azure Cloud Shell menu, choose Bash, and allow Azure to restart the container. Yes, you heard me correctly - Azure Cloud Shell itself runs as a container. Per Scott Hanselman, who works Microsoft’s Web Platform Team, we can confirm that Azure Cloud Shell runs an Ubuntu (Debian) Linux Docker container, which in turn runs the bash shell:

timothy@Azure:~$ ps
  PID TTY                 TIME       CMD
   99 pts/0           00:00:00       bash
  114 pts/0           00:00:00       ps

timothy@Azure:~$ lsb_release -a
No LSB modules are available.
Distributor ID:        Ubuntu
Description:           Ubuntu 16.04.2 LTS
Release:               16.04
Codename:              xenial
timothy@Azure:~$

According to Scott, it is the xterm.js JavaScript library that powers the browser-based terminal. With regard to the cloud drive, the Azure file share is mounted directly within your home directory. For instance:

timothy@Azure:~$ pwd
/home/timothy
timothy@Azure:~$ ls
clouddrive
timothy@Azure:~$ cd clouddrive
timothy@Azure:~/clouddrive$ ls
myscript.ps1
timothy@Azure:~/clouddrive$

Do you see the PowerShell script? This is a single, persistent storage area between both the bash and the PowerShell containers.

Get started with Azure CLI v2.0 by using the interactive shell; do so by running the az interactive command. In Figure 7 you can see me doing some virtual machine (VM) maintenance and receiving autocomplete guidance from the interactive shell.

Figure 7. Azure CLI v2.0 interactive shell.

Tips and tricks

Of course you're going to want to use copy and paste. Don't try CTRL+C or CTRL+V. Instead, use:

  • CTRL+INSERT to copy
  • SHIFT+INSERT to paste

Depending on your browser, you can use mouse selection and the right-click context menu as well.

Azure Cloud Shell times out after 20 minutes of inactivity. Press ENTER to resume your session.

In addition to Azure PowerShell and Azure CLI v2.0, the Azure Cloud Shell containers include a number of useful software programs. Here is a sampling from the bash environment:

  • Docker
  • Dotnet (.NET Core command-line interpreter)
  • Emacs
  • Git
  • iPython
  • Kubectl
  • Make
  • Mysql
  • Nodejs
  • Npm
  • Pip
  • Postgres
  • Sqlcmd
  • SSH
  • Vim

Understand that in the bash shell you run as a standard user without (admin)sudo access. Any software you install outside your home directory will not persist across sessions.

In the PowerShell environment, you have access Windows versions of most of the previously listed administrative and development tools. Run the following two commands to check our the container's software inventory:

Set-Location -Path C:\

Get-ChildItem -Path . -Recurse -Filter *.exe

Let me leave you with some Azure Cloud Shell supplemental resources to keep you moving along your learning curve. Take good care!


Timothy Warner is a Microsoft Most Valuable Professional (MVP) in Cloud and Datacenter Management who is based in Nashville, TN. His professional specialties include Microsoft Azure, cross-platform PowerShell, and all things Windows Server-related. You can reach Tim via Twitter @TechTrainerTim, LinkedIn or his personal website, techtrainertim.com.

Comments (0)

Skip to main content