Install Azure CLI On Windows

Install Azure CLI On Windows

In this Azure tutorial, we will discuss Install Azure CLI On Windows, Along with this, we will also discuss a few other topics like below

  • What is Azure CLI?
  • Key Features of Azure CLI
  • Update Azure CLI Version
  • Azure CLI login
  • Install Azure CLI Mac.
  • Azure CLI vs PowerShell.
  • Unable to locate package azure-cli

Install Azure CLI On Windows

Well, Let’s discuss an interesting topic i.e Install Azure CLI On Windows. But before starting the installation what if we will discuss What is Azure CLI ?.

What is Azure CLI ?

The Azure CLI is termed as Azure command-line interface. This is nothing but a set of commands that actually helps us to create and manage all our Azure Resources. That is designed in such a way that it gets you working quickly with Azure.

Key Features of Azure CLI

Below are few key features of the Azure CLI

  • Provides the command-line interface to manage different Azure solutions.
  • It supports different operating systems like Windows, Linux, and macOS.
  • It provides you the facility to work with different clouds.
  • Azure CLI can fit with the long-running operations.
  • Provides the configurations for the logging, data collection, etc.

Assuming we have a bit idea on Azure CLI, let’s start with the main topic i.e Install Azure CLI On Windows.

You can install the Azure CLI On Windows in two ways.

  • Use the Microsoft Installer (MSI)

You can download the Azure CLI exe file from the below path and install that in your machine

https://aka.ms/installazurecliwindows

Once you will access the above URL, it will prompt you to save the Azure CLI exe file in your local path. It will take a few minutes to download the exe file. Once you download the exe file, You can double click on the exe file to install the Azure CLI set up.

How to Install Azure CLI On Windows

Now, as the next step, select the “I accept the terms in the License Agreement” option and then click on the Install button to start the installation process.

install azure cli on windows without admin rights
  • Microsoft Installer (MSI) with PowerShell command

Another way is to install the Azure CLI using the PowerShell cmdlet. you can use the below PowerShell cmdlet to install the 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

Note: One important thing to note down here is. If you have already installed the Azure CLI on your machine and you are trying to run the PowerShell cmdlet on top of that then it will update the Azure CLI to the latest version.

After executing the script, you might get the error ” Invoke-WebRequest: The operation has timed out”. The complete error message is as below.

Invoke-WebRequest : The operation has timed out.
At line:1 char:1

  • Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile …
  • ~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebReq
      uest) [Invoke-WebRequest], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Comm
      ands.InvokeWebRequestCommand

But if you will try executing the same script once or twice, it will definitely work for you and Azure CLI will install successfully for you without any issue. This is how we can install Azure CLI On Windows.

Update Azure CLI Version

Suppose you have already the Azure CLI installed on your machine and you want to upgrade to the latest version of Azure CLI, then you can execute the below PowerShell cmdlet to upgrade the Azure CLI version to the latest one.

az upgrade

Run the Azure CLI

Ohk, till now we have done with the installation of Azure CLI and then we have discussed how to update the Azure CLI version. Now Let’s discuss How to run the Azure CLI. You can use the Windows command prompt or PowerShell to execute the commands. Follow the below steps to run the Azure CLI.

Step-1: Run the below az command to login

az login

 Once you will execute the above PowerShell cmdlet, it will prompt you to sign in with the Browser.

Step-2: Enter your account credentials to log in.

Uninstall Azure CLI

If By chance, you have decided to uninstall the Azure CLI, then you can uninstall the Azure CLI using the below steps.

  • If you are using Windows 10, To uninstall the Azure CLI, Navigate to Start > Settings > Apps.
  • If you are using Windows 7 or Windows 8, To uninstall the Azure CLI, Navigate to Start > Control Panel > Programs > Uninstall a program.

Azure CLI login

While working with the Azure CLI, you can sign in with the help of the Browser with the az login command as discussed above. you can use the below PowerShell cmdlet

az login

Once you will execute the above Azure CLI command, you need to enter your Account credentials to log in. But with the command itself, you can also provide your credentials to log in to the Azure CLI. you can use the az login command along with the username and password like below.

az login -u <username> -p <password>

It is obvious that you don’t want to display the password openly. So avoid this scenario, you can use the PowerShell cmdlet like below

$Cred = Get-Credential -UserName <Enter your username>
az login -u $Cred.UserName -p $Cred.GetNetworkCredential().Password

Once you will execute the above command, you will get something like below

Update Azure CLI Version
azure cli powershell

Sign in Azure CLI with a service principal

You can also sign in with the service principal. To give you a glance at the service principal. Service Principals are the accounts that are not tied to any specific user that can have permissions on them assigned via predefined roles. Using the service principal to log in is one of the most secure ways.

There are few things that you need to sign in with a service principal

  1. The URL or the name that is actually associated with the service principal.
  2. You need the X509 certificate or the service principal password.
  3. You need the tenant that is associated with the service principal.

The PowerShell cmdlet will be like below

az login --service-principal -u <app-url> -p <password-or-cert> --tenant <tenant>

If you don’t want to display the details to the outer world, you can use the PowerShell cmdlet like below

$Cred = Get-Credential -UserName <app-url>
az login --service-principal -u $Cred.UserName -p $Cred.GetNetworkCredential().Password --tenant <tenant>

Sign in with a different tenant

You can also sign in with a different tenant. You need to specify the tenant name with the –tenant parameter.

az login --tenant <tenant>

Sign in with a managed identity

One more way to log in is to sign in with a managed identity. Below is the cmdlet that you can use to sign in with a managed identity.

az login --identity

So, this is all about Azure CLI login.

Install Azure CLI Mac

Well, above, we have discussed How to install Azure CLI in Windows?. Now, let’s discuss How to Install Azure CLI on macOS. Homebrew is an excellent way to manage the Azure CLI installation on the macOS. So the first step is to install the Homebrew if you don’t have Homebrew installed on your machine.

Installing Homebrew

You can install the Homebrew on your machine by following the instruction on the official website. As per the instruction mentioned on the website, you need to open the terminal and run the below cmdlet

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Once you will install the Homebrew in your machine. Then with the help of the Homebrew, we can easily install the Azure CLI on the macOS.

Installing Azure CLI for Mac

Now we are ready to install the Azure CLI on the macOS. Now you can use the below cmdlet to install the Azure CLI on the macOS.

brew update && brew install azure-cli

To check the installation has completed properly, you can use the below cmdlet

az

The next step is try to login into your Azure account using the below cmdlet

az login

Once you will execute the above cmdlet, it will prompt you to enter your Azure credential details to sign in.

Azure CLI vs PowerShell

Before discussing the Azure CLI vs PowerShell. We need to know a little background on both Azure CLI and Azure PowerShell. The main point here is both Azure CLI and Azure PowerShell are available in the Azure cloud. You can also use both of them remotely from your local machine.

To locate the Azure Cloud Shell, you can log in to the Azure Portal and click on the Cloud Shell icon as highlighted below which is present just before the Directory + Subscription button.

Azure CLI vs PowerShell

Once you will click on the Cloud Shell, it will give you the option, either you can use Bash or PowerShell based on your requirement.

Azure CLI is a command-line tool that connects to Azure and executes different administrative commands on the different Azure resources. you can use the same commands for whatever platform you want to use like Windows, Linux or Mac, etc.

There are two versions of Azure CLI that are present now. The first one is the Azure CLI version 1.0 which is written with Node.js and the other Azure CLI version is 2.0 which is actually written in Python to support the better cross-platform capabilities. Azure CLI can also be used with Groovy, Python, Ruby, or any other scripting language.

Whereas PowerShell is a great choice for the Azure Functions and Azure Automation Runbooks and you can’t use the Azure CLI here.

PowerShell has very excellent multithreaded workload support. PowerShell is very suitable for any of the quick script requirements.

Microsoft keeps on revising the Azure PowerShell modules. Now we have the az PowerShell module to perform many activities to manage the Azure resources.

Unable to locate package azure-cli [Soluton]

There might be a chance that you will get an error “Unable to locate package azure-cli” . I have fixed the same issue by running the below cmdlet

sudo apt-get update && sudo apt-get upgrade

You may also like following the below articles

Wrapping Up

In this article, we have discussed Install Azure CLI On Windows. Along with this, we have also discussed What is Azure CLI ?, Key Features of Azure CLI, Update Azure CLI Version, Azure CLI login, Install Azure CLI Mac. Finally, we have discussed Install Azure CLI Mac, Azure CLI vs PowerShell, Unable to locate package azure-cli. I hope, you have enjoyed this article !!!