There are many ways you can manage Azure, for example, by using the Azure PowerShell, Cloud Shell, or many other tools. One of them is the Azure CLI, which is a command-line tool providing a management experience for Azure resources. In this blog post, I will show you how you can download, install, and update the Azure CLI on Windows with a simple PowerShell one-liner.
Installation
First, if you want to install the CLI, on Windows, Linux or other platforms, we have some excellent documentation on this on Microsoft Docs.
- Install on Windows
- Install on macOS
- Install on Linux or Windows Subsystem for Linux (WSL)
Install Azure CLI on Windows using a PowerShell One-liner
Instead of downloading the MSI file manually and install it on your Windows 10 machine, you can run the following PowerShell one-liner to install the Azure CLI. Start PowerShell as administrator and run the following command:
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'
This will download and install the latest version of the Azure CLI for Windows. If you already have a version installed, it will update the existing version. Reopen PowerShell or the command prompt to start using it, and just type:
az
If you are running behind a proxy, make sure you configure your proxy settings.
Run Azure CLI on Windows using a Docker Container
If you have Docker installed, you can also run the CLI in an isolated environment using the mcr.microsoft.com/azure-cli container image and run the following command:
docker run -it mcr.microsoft.com/azure-cli
You can also use the container image as a base for your custom container image. Little fun fact, the container image is based on Linux, and with Linux containers on Windows, it runs great on Windows 10. You can find more information about running the CLI in a Docker container, on Microsoft Docs.
Configuration
After the CLI is installed, you can also configure some default settings.
One of the settings which I really like to change is the default output from JSON to table. However, you can configure it the way you like it.
az configure
To manage your Azure resources you now need to log in using the login command.
az login
After the login, you will run the commands in the context of the specific user, and start working with your Azure resources.
Azure PowerShell vs. Azure CLI
I often get asked by customers, which one should they use. The short answer is: it depends. I am a long-time PowerShell user, so PowerShell is more natural to me when it comes to scripting. But if someone is using different CLIs in the past, he might prefer the CLI experience. I personally love that PowerShell gives me objects and especially in scripts, this makes things much easier for me. However, when it commands to do something in a one-liner quickly, the Azure CLI experience often works better for me. So it really depends on what you prefer, Microsoft gives you a choice to use whatever works best for you. Yes, not all services are indeed available in both of them. Especially when the service is in preview, it can happen that you only have one of them available. However, the teams are working hard to bring services to both experiences.
By the way, you can always run the latest version in the Azure Cloud Shell. And you can see this runs great if in the newest preview of the new Windows Terminal.
I hope this helps you installing the Azure CLI on Windows if you have any questions feel free to leave a comment.
Tags: az configure, Az login, Azure, Azure CLI, Container, Docker, download, install, Install Azure CLI, installation, Linux, Microsoft, PowerShell, Run, update, Windows, Windows 10, Windows Terminal Last modified: July 30, 2019
Hello Thomas,
Thank for sharing the article.
I am working on one automated process to upload a file using az CLI to Azure blob.
When the user run’s the script for the first time if there is no azure CLI installed on the user machine. I am installing(find below code), But the requirement here is after installing azure CLI from PowerShell and it should not restart and allow the user to execute the az login command.
Code for your reference :
Function Set-AzModule(){
$isAzureCliInstalled = Azure-CLI-Installed
Set-AzCopyVariables
if (!$isAzureCliInstalled) {
Write-Log “Trying to install Microsoft Azure CLI”
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList ‘/I AzureCLI.msi /quiet’; rm .\AzureCLI.msi
$isAzureCliInstalled = Azure-CLI-Installed;
if (!$isAzureCliInstalled) {
Write-Log -message “Unable to install Microsoft Azure CLI”
}
else {
Write-Log -message “Microsoft Azure CLI installed successfully”
az login
## Here the command is failing power shell not able to find the az module
}
}
}
Function Azure-CLI-Installed()
{
# Check Microsoft Azure CLI is installed or not.
return (Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
Where { $_.DisplayName -eq “Microsoft Azure CLI” }) -ne $null
}
Please help me on this.
Hi @Moueen,
try this
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi
Start-Process msiexec.exe -Wait -ArgumentList “/a AzureCLI.msi /qb TARGETDIR=$env:APPDATA\azure-cli /quiet”
if (!($env:Path -like ‘*CLI2\wbin*’))
{
$Remove = ‘C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin’
$env:Path = ($env:Path.Split(‘;’) | Where-Object -FilterScript {$_ -ne $Remove}) -join ‘;’
}
$env:path=”$env:APPDATA\azure-cli\Microsoft SDKs\Azure\CLI2\wbin;”+$env:path
rm .\AzureCLI.msi
az –version 2>$null
And, with az version 2.11 and above you may use
az upgrade –yes –all 2>&1 | out-null