Pearls of wisdom for cloud admins: Exploring Azure Cloud Shell

Microsoft Azure can be managed from Microsoft Azure Portal, PowerShell, cross-platform command line interface (CLI), and all those interfaces that use Rest API to manage resources. Currently, there is an Azure Cloud Shell (preview) feature that combines Azure Portal capabilities with PowerShell. In summary, we can have a shell prompt running in the Azure Portal session or in the Microsoft Azure Mobile app. Cloud Shell will use our preferred method (bash or PowerShell) and manage Azure Resources using commands in Azure Resource Manager (ARM). And there are also some additional tools available to help the cloud administrator.

Another benefit of using Azure Cloud Shell is that it uses a Storage Account to store files and important information, although a new instance of a virtual machine will be created every time that we open a Cloud Shell (currently Cloud PowerShell runs on Windows Server 2016) but all the data will be available because a connection to the Storage Account will be performed creating a consistent and resilient experience for the Cloud Shell user.

Starting with Azure Cloud Shell

The first step is logged on your Azure Portal, click on the Azure Cloud Shell icon located at the top of the portal. If this is your first time, you will be prompted to select which type of shell you are going to use. Click on your preference.

azure cloud shell

A new page will be displayed. The Azure Cloud Shell requires a file share in a Storage Account, ao we need to select the subscription and then click on Create Storage.

The result of running the Azure Cloud Shell for the first time is a creation of a Resource Group called cloud-shell-storage-<region> and also a Storage Account with prefix cs in the same Resource Group.

The Storage Account will have a file share with the prefix cs and within that share, a folder called .pscloudshell, and that folder by default has three subfolders: .azure, PowerShell, and WindowsPowerShell. They can be used to store modules and files in general that can be used during an Azure Cloud Shell session.

We can use the interface below to add files that can be used later by Cloud Shell. We are going to check in our next section how to work with those folders from the Azure Cloud Shell perspective.

azure cloud shell

Getting acquainted with Azure Cloud Shell

After starting Azure Cloud Shell for the first time, the Resource Group, Storage Account, File Share, and folders will be created automatically as part of the process (item 2 in the image depicted below).

Note: We can check at any time the storage information associated with the current Azure Cloud Shell by running the Get-CloudDrive cmdlet.

The Azure Cloud Shell has a simple menu (item 1 below), which allows the administrator to change the shell (bash or PowerShell), restart the session, change the text size and font, create a new tab (it will open a tab on the browser in full screen), and upload a file, which is really handy when you have a script ready to go on your workstation and need to execute in Azure Cloud Shell.

azure cloud shell

By the way, if you are using the Microsoft Azure app, you will notice that there is a Cloud Shell icon, and all features available on a regular web browser are also supported in the app. In the image below, we created a new Resource Group using New-AzureRMResourceGroup cmdlet and we also list all resource groups by name.

azure cloud shell

In the previous section, we saw that some folders are created in the Azure File Share and that storage is always connected to the Azure Cloud Shell. The nagging question that you may be asking yourself right now is… OK, but how do I see that in the Azure Cloud Shell?

The answer is simple. We can just type cd $Home\CloudDrive from the Azure Cloud Shell and we will be on the context of that Azure File Share and we can edit (yes, we can use editors in Azure Cloud Shell!), upload files, and use them.

Keep in mind, by default you are in the Azure:\ context. When you go to the Azure File Share we will enter the PS C:\, which is on the VM that is supporting the current session. To return to the Azure context, just type cd Azure: and you are back to the original place.

Listing resources using Azure Cloud Shell

One of the great features of Azure Cloud Shel is the ability to use dir and cd commands to navigate under the subscription/areas, and within the subscription we can list All Resources, Resource Groups, Storage Accounts, Virtual Machines and Web Apps by just typing cd VirtualMachines and then dir to list all resources of that given type.

azure cloud shell

Another useful resource is the cmdlet Get-AzureRMCommand, which will list all commands that are applicable on the current context. Let’s say that we went to VirtualMachines. When we run the Get-AzureRMCommand all cmdlets that are applicable to a virtual machine will be listed.

One last trick before moving forward: We can list all the cmdlets of any given module by running the following cmdlet: Get-Command -Module AzureAD, in this example we use the AzureAD module.

Using Cloud Shell tools

Besides giving easy access to Azure Resource Manager and PowerShell cmdlets, we have several tools to help the administrator to complete tasks without getting too much trouble gathering tools to be used in any given session.

A good example is the Azure Cross-Platform Command Line Interface (CLI). We can just type AZ and we will have access to it.

Another cool feature is the text editors available in Azure Cloud Shell, which are vim (my favorite from my previous life compiling Linux kernels) and nano, which is more user-friendly.

When using the text editor, we can take advantage of the IntelliSense feature to complete the cmdlets that we are planning to use in our upcoming script, as depicted in the image below.

azure cloud shell

Notes from the field

In this article, we explored some of the cool features of Azure Cloud Shell and how they can help an administrator perform activities without using local PowerShell, which makes administration a breeze.

We can use shell.azure.com from a supported browser and after authenticating the account we have access to Cloud Shell.

Another nice feature that we haven’t touched on this article because it deserves an article just for that is the ability to run commands on VMs using the Invoke-AzureRmVMCommand. Stay tuned!

Leave a Comment

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top