Checklist of Azure tools for enterprise admin: PowerShell, AzCopy, Azure CLI, Docker, Git, Azure Providers

powershellAzure provides the Azure Cloud Shell which includes almost every tool you will need already installed. But that requires you to be logged into the portal. And it times out after a short time. So you can administer Azure from your desktop.

There are tools you will normally want on your local computer to administer Azure:

  • PowerShell
  • Azure Powershell
  • Azure CLI and some additional tools (such as jq and Kubernetes)
  • AzCopy
  • Git
  • Docker
  • Visual Studio Code and extensions

All are cross platform tools. In this article, you will learn how to install the tools from the command line. And you will learn about Azure providers and how to add them to your subscription.

The purpose of this article is to provide a set of steps that you can use to get started using Azure from the command line. Tools change quickly, so the exact versions and the tooling can change. The point of the article is to provide a checklist and a set of tools that you will need as an cloud engineer.

Install or update PowerShell

PowerShell Core is a cross-platform (Windows, Linux, and macOS) automation and configuration tool/framework. PowerShell itself is now Open Source on GitHub.

The instructions on how to install are on the GitHub PowerShell. The site provides the links and instructions for how to install or update your PowerShell.

For detailed scripts on how install PowerShell in your automation on for your particular environment, see Installing various versions of PowerShell.

If you’re on Windows 10, you already have PowerShell 5.1 installed, which is high enough to install the Az module. You should be running version 7.0 or later. To check your version from inside PowerShell application, use $PSVersionTable. If you are on a command line, use:

powershell -command "(Get-Variable PSVersionTable -ValueOnly).PSVersion"

To see other ways to check, see How to Check the Current PowerShell Version.

Learn more about PowerShell, see Learning PowerShell on GitHub.

Install PowerShell for Azure using Scripts

Next, install Azure PowerShell. There are two PowerShell modules that support of Azure PowerShell, AzureRM and Az modules. You cannot have both installed at the same time. You should only use the Az module going forward. Install the Azure PowerShell module describes in detail how to check and install it.

The following PowerShell script shows how to install Az PowerShell and several other modules that you will need in other aricles in this blog.

#Requires -Version 7.0
#Requires -Modules PowerShellGet
# you may need to agree to accepts signed PowerShell modules
Set-ExecutionPolicy ExecutionPolicy AllSigned
# From https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-3.6.1
if ($PSVersionTable.PSEdition -eq 'Desktop' -and (Get-Module Name AzureRM ListAvailable)) {
Write-Warning Message ('Az module not installed. Having both the AzureRM and ' +
'Az modules installed at the same time is not supported.')
} else {
Install-Module Name Az AllowClobber Scope CurrentUser Force
Install-Module Name Az.Blueprint Scope CurrentUser Force
Install-Module Name Az.Security Scope CurrentUser Force
Install-Module Name Az.OperationalInsights Scope CurrentUser Force
Install-Module Name Az.Network Scope CurrentUser Force
Install-Module Name azuread Scope CurrentUser Force
}

The script uses -Scope CurrentUser. To install for all users, use -Scope AllUsers paramter and start PowerShell as admin or sudo on the Mac. It also uses the -Force parameter which is used to reinstall the modules. You will find that the versions of the modules may get updated separately.

You will need to agree to install from PowerShell Gallery.

Log into Azure using PowerShell

You can now log into Azure using PowerShell.

# Connect to Azure with a browser sign in token
Connect-AzAccount

view raw
start-azure.ps1
hosted with ❤ by GitHub

Note that Connect-AzAccount can have parameters to specify a particular tenant, subscription, or to provide credentials using a service principal or managed identity. See Connect-AzAccount.

Install Azure CLI

You will want to install the Azure CLI and some additonal tools, such as jq and the Azure Kubernetes CLI.

You can install the Azure CLI on Windows, macOS and Linux.

To install on Windows from a script, you can use:

Invoke-WebRequest Uri https://aka.ms/installazurecliwindows OutFile .\AzureCLI.msi; Start-Process msiexec.exe Wait ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi

To install on Linux, use:

Log into Azure using Azure CLI

Once Azure CLI is installed, you can log in using:

az login

view raw
log-in-azure-cli.sh
hosted with ❤ by GitHub

If the CLI can open your default browser, it will do so and load an Azure sign-in page. Otherwise, open a browser page at https://aka.ms/devicelogin and enter the authorization code displayed in your terminal.

NOTE: You can run Azure CLI commands from inside PowerShell. But Azure recognizes either the CLI log in or the PowerShell log in for its session state. And while you can mix or match tooling to some extent, you can use only the CLI using the CLI log in or the Azure PowerShell from the AzConnect-Account login.

Add to CLI

There are several additons to the Azure CLI, you will want:

  • jq. Use it to slice and filter and map and transform the values the CLI returns in JSON.
  • If you wan to use Azure Kubernetes Service, you will need an additonal module to log into kubectl.
Install jq

The scripts in this blog need jq to parse the JSON that is returned by the Azure CLI. jq is a command line JSON processor; with it you can map, filter, slice, and transform JSON. The documentation shows how to download JQ.

If you are running in WSL 2 on Windows (Windows Subsystem for Linux) or in Linux, you can install jq using the following Bash script:

# for Ubuntu 14 and above
sudo apt-get install jq

view raw
install-jq.sh
hosted with ❤ by GitHub

Install Kubernetes for CLI

It is intended for this blog to discuss Kubernetes at length, particularly Azure Kubernetes Service (AKS). You will need to install

az aks install-cli

view raw
install-aks.sh
hosted with ❤ by GitHub

Once you install your cluster, which is the subject of future articles, you can log into the cluster using something like:

az aks get-credentials –resource-group $RESOURCEGROUPNAME –name $AKSCLUSTERNAME
kubectl get nodes

view raw
connect-to-aks.sh
hosted with ❤ by GitHub

Install AzCopy

AzCopy is a command-line utility that you can use to copy blobs or files to or from a storage account. It uses concurrency to scale up according to the number of machine’s logical cores. And if the connect drops, you can restart it without having to start over.

The following code can be used to install AzCopy using PowerShell:

### Adapted from https://www.thomasmaurer.ch/2019/05/how-to-install-azcopy-for-azure-storage/
$destimationPath = [Environment]::GetFolderPath("MyDocuments")
#Download AzCopy
Invoke-WebRequest Uri "https://aka.ms/downloadazcopy-v10-windows" OutFile AzCopy.zip UseBasicParsing
#Curl.exe option (Windows 10 Spring 2018 Update (or later))
# curl.exe -L -o AzCopy.zip https://aka.ms/downloadazcopy-v10-windows
#Expand Archive
Expand-Archive ./AzCopy.zip ./AzCopy Force
#Move AzCopy to the destination you want to store it
New-Item ItemType directory Path $destimationPath\Azure\AzCopy
Get-ChildItem ./AzCopy/*/azcopy.exe | Move-Item Destination $destimationPath\Azure\AzCopy\AzCopy.exe
#Add your AzCopy path to the Windows environment PATH using PowerShell:
Set-Item Path Env:Path Value ($Env:Path + ";" + $destimationPath + "\Azure\AzCopy")
$env:Path -split ';'

view raw
install-azcopy.ps1
hosted with ❤ by GitHub

To install manually, see Get started with AzCopy.

To use AzCopy, see azcopy for all the command line parameters.

Install or update Git

Follow the Git install documentation, which recommends that even if you have Git installed, you should update it.

On Windows go to https://git-scm.com/download/win and the download will start automatically. Note that this is a project called Git for Windows

On Ubuntu or on WSL on Windows:

sudo apt install git-all

view raw
install-git.sh
hosted with ❤ by GitHub

Install Docker

You can develop, build and run your code in Docker containers on your desktop and they will work the same in the cloud.

Docker Desktop is an application for Mac or Windows desktop for you to build and share containerized applications and microservices.

Docker Desktop on Windows

Use the instructions on Install Docker Desktop on Windows. The steps consist of:

  1. Downloading the Docker zip file
  2. Enabling Hyper-V Windows Features
  3. Install Docker
  4. If your admin account is different to your user account, you must add the user to the docker-users group.
  5. Start Docker

Once you install Docker on your desktop, you will be able to see it from PowerShell or WSL or the command line. (WSL 2 runs inside Docker.)

Docker Desktop on Mac

Docker Desktop for Mac is the Community version of Docker for Mac. You can download Docker Desktop for Mac from Docker Hub.

Docker installation on Ubuntu

Use the Windows Docker Decktop installation if you are running WSL. Otherwise, use the documentation at Install Docker Engine on Ubuntu, which consists of several steps. Basically the steps:

  1. Set up the repository by updating apt, add Docker’s official GPG key, add Docker’s apt repository.
  2. Install Docker Engine using apt-get

In production, you will want to review the installation scripts before running.

Install Visual Studio Code

Download Visual Studio Code from the installation page for Linux, Mac, or Windows.

To install in WSL or on Ubuntu:

# Update the packages index and install the dependencies
sudo apt update
sudo apt install software-properties-common apt-transport-https wget
# Import the Microsoft GPG key
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add –
# Enable the Visual Studio Code repository
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
# Install the latest version of Visual Studio Code with:
sudo apt update
sudo apt install code

view raw
install-vscode.sh
hosted with ❤ by GitHub

With WSL, you can install and run Linux distributions on Windows. Add Remote – WSL extension, to get full Visual Studio Code editing and debugging support while running in the context of a Linux distro on WSL. See Developing in WSL to learn more. Try the Working in WSL step-by-step tutorial.

Start Visual Studio Code

To start code, go to the directory you want to use and type code.

Visual Studio Code Extensions

Before we start, Visual Studio Code supports Git by default, which means you don’t have to install any packages or extensions to use it. See Git Support.

The power of VS Code comes from the developer-supported extensions. Extensions will help with code highlighting, executing commands from within Code, and Intellisense.

Some interesting extensions:

  • Docker helps you edit Dockerfile, docker-compose files. It also provides one-click debugging of Node.js, Python, and .NET Core inside a container.
  • Kubernetes for developers building applications to run in Kubernetes clusters and for DevOps staff troubleshooting Kubernetes applications.
  • Azure CLI provides IntelliSense for commands and their arguments.
  • Terraform provides Terraform command support, resource graph visualization and CloudShell integration inside VSCode.
  • Deploy to Azure helps you set up continuous build and deployment for Azure App Service or for Azure Kubernetes Service without leaving Visual Studio Code.
  • Python offers IntelliSense, linting, debugging, code navigation, code formatting, Jupyter notebook support, refactoring, variable explorer, test explorer, snippets, and more.
  • Git Graph for you to view a Git Graph of your repository, and easily perform Git actions from the graph.

You can list, add, and remove extensions from the command line:

# Set the root path for extensions
code –extensions-dir <dir>
# List the installed extensions.
code –list-extensions
# Install extension
code –install-extension (<extension-id> | <extension-vsix-path>)
# Uninstalls an extension.
code –uninstall-extension (<extension-id> | <extension-vsix-path>)

view raw
code.sh
hosted with ❤ by GitHub

When identifying an extension, provide the full name of the form publisher.extension, for example ms-python.python.

Install additonal Azure Providers

An Azure Provider is a set of services provided by Azure.

For example, if you want to store keys and secrets, you work with the Microsoft.KeyVault resource provider. This resource provider offers a resource type called vaults for creating the key vault.

For a list of the names of the providers and how they match to the services you need, see Resource providers for Azure services.

Not all providers are deployed in your subscription by default. From time to time, you will need a provider.

To see what providers are installed, use the following code in PowerShell:

Get-AzResourceProvider ListAvailable | Select-Object ProviderNamespace, RegistrationState

To see what providers are installed, use the following code using the Azure CLI:

az provider list –query "[].{Provider:namespace, Status:registrationState}" –out table

If the service provider you want is not installed, you will need to register it. For example, the following PowerShell script registers Azure Batch.

Register-AzResourceProvider ProviderNamespace Microsoft.Batch

Or in Azure CLI:

az provider register –namespace Microsoft.Batch

For more details, see Azure resource providers and types.

Summary

In this article you have a good set of steps to get set up as an cloud admin for Azure. The scripts are meant to be suggestive and may need to be updated by the time you read this. But I hope you will find the checklist useful.

Windows now has a package manager as slick as apt is on Linux. The new Windows Package Manager may make it much easier to get all of this installed on Windows in the future.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s