Skip to content

Azure Cloud Shell

What Where
Official Page https://azure.microsoft.com/en-us/features/cloud-shell/
Docs https://docs.microsoft.com/en-us/azure/cloud-shell/overview
Online https://shell.azure.com/ https://portal.azure.com/#cloudshell/
Cloud Shell Tools https://docs.microsoft.com/en-us/azure/cloud-shell/features https://build5nines.com/azure-cloud-shell-tips-and-tricks/

Further Links

Cloud Shell options

There are three options to use the cloud shell: Docker, Windows Terminal and the Azure Web Interface:

Docker

You get a CloudShell container as follows:

docker run -it mcr.microsoft.com/azure-cloudshell /bin/bash # for bash
docker run -it mcr.microsoft.com/azure-cloudshell /usr/bin/pwsh # for powershell

Windows Terminal

The Windows terminal has the cloud shell integrated. Aside from other features this is a good way to interact with azure on command line.

Install the windows terminal withchoco install microsoft-windows-terminal. You need to login to azure first to use the terminal.

Azure Portal

Go to https://shell.azure.com and you are logged in with your current user.

To get a GUI editor in the web runcode ..

Attach Storage

  • Add FileShare to Cloud Shell: clouddrive mount -s <secret> -g <rg-name> -n <fileshare> -f <share>
  • Show Drives: Get-CloudDrive
  • Remove or re-configure your cloud drive: dismount-clouddrive

Sources:

Connect to VM console

You can access an Azure VM within the Azure Cloud Shell. https://docs.microsoft.com/de-de/azure/cloud-shell/quickstart-powershell

Enable remoting if not yet done:

Enable-AzVMPSRemoting -Name MyVM1 -ResourceGroupname MyResourceGroup

Execute script on VM:

Invoke-AzVMCommand -Name MyVM1 -ResourceGroupName MyResourceGroup -Scriptblock {Get-ComputerInfo} -Credential (Get-Credential)

Enter VMs commandline:

Enter-AzVM -Name MyVM1 -ResourceGroupName MyResourceGroup -Credential (Get-Credential)

Basic Settings

Set default context for Azure PowerShell

Update-AzConfig -DefaultSubscriptionForLogin abcdef-1111-...

Disable the survey message

Update-AzConfig -DisplaySurveyMessage $false

Enable the breaking change warning message

Update-AzConfig -DisplayBreakingChangeWarning $true

Disable region recommendation message

Update-AzConfig -DisplayRegionIdentified $false

Disable sending telemetry data to Microsoft

Update-AzConfig -EnableDataCollection $false

Disable Web Account Manager as default default interactive login

Update-AzConfig -EnableLoginByWam $false

Export Settings

Export-AzConfig -Path $HOME\AzConfig.json

The exported settings look like this:

{
    "Az": {
        "EnableDataCollection": false,
        "DisplaySurveyMessage": false,
        "DisplayBreakingChangeWarning": true,
        "DisplayRegionIdentified": false,
        "EnableLoginByWam": false,
        "DefaultSubscriptionForLogin": "abcdef-1111-..."
    }
}

To import the settings run this:

Import-AzConfig -Path $HOME\AzConfig.json

Enhance CloudShell Bash

Az Predictor is a PowerShell module that helps you navigate the cmdlets and parameters of the Az PowerShell module. It provides intelligent context-aware suggestions for command completion when using Azure PowerShell.

Install-Module -Name PSReadline
Install-Module -Name Az.Tools.Predictor
Enable-AzPredictor -AllSession
Set-PSReadLineOption -PredictionViewStyle ListView

Posh-Git provides us with information at the command line about the state of the current repository we are in. It also provides tab completion for Git commands.

install-module posh-git
import-module posh-git

Oh-My-Posh allows you to theme your prompt with various color schemes, Git status indicators, Admin status and many other things. <>

Install-Module oh-my-posh
Import-module oh-my-posh

Get-ChildItemColor is a simple tool which adds color coding to the get-childitem command. When you run this command, you get different colors used for folders vs. files and different file types.

Install-Module Get-ChildItemColor
Import-Module Get-ChildItemColor