The Azure Command-Line Interface (CLI), formerly known as the cross-platform CLI (Xplat-CLI) is an open-source project that gives us command-line access to our Azure resources from just about any desktop operating system.

Timothy Warner

Timothy Warner is a Microsoft Cloud and Datacenter Management Most Valuable Professional (MVP) who is based in Nashville, TN. Check out his Azure and Windows Server video training at Pluralsight, and feel free to reach out to Tim via Twitter.

I’m almost positive you know how robust the Windows PowerShell support is in Microsoft Azure. With the release of Azure PowerShell v1.0, you can accomplish just about every administrative task in either the classic service management or new-ish Resource Manager deployment models.

As awesome as Windows PowerShell is, we’re left with a question: how can we access our Azure resources via a command prompt when we’re working in Linux or OS X? Yeah, we can bring up a Windows virtual machine or start an RDP session, but that defeats the purpose of administrative automation. Well, enter the Azure Command-Line Interface (CLI).

To get started, visit the Azure Software Development Kits (SDKs) and Tools page and download the Azure CLI installer (scroll down to Command-line tools / Azure command-line interface) that’s appropriate for your OS. The Azure Documentation has clear instructions for performing Linux-based installations and invoking the Azure CLI from a Docker container.

I want to prove to you that the Azure CLI is truly cross-platform, so I’ll be working from my Apple iMac running OS X El Capitan. Microsoft did a good job with their OS X installer!

Installing the Azure CLI on my Mac

Installing the Azure CLI on my Mac

Logging in and logging out ^

At your command line (Terminal in OS X or Linux; elevated PowerShell console on Windows), simply type azure to view the “welcome” page. By the way, the output is exactly the same, regardless of your OS.

The Azure CLI welcome text

The Azure CLI welcome text

Logging in to your Azure subscription involves four steps:

  1. Running the command azure login
  2. Navigating to the sign-in web page
  3. Submitting your access token
  4. Returning to the Azure CLI session

For instance, this is the output I received when I ran azure login on the Mac:

I needed to copy the URL link (OS X actually allows you to click hyperlinks directly from the Terminal window) to a browser and submit the access token. When I did this on Windows, I was also required to submit my Azure username and password.

Azure CLI uses a browser-based authentication method

Azure CLI’s browser-based authentication method

You can use the publish settings file approach if you need to automate connecting to your Azure subscription. Also, my scope in today’s lesson will be strictly in service management rather than resource management.

After login, you’ll receive information about your Azure subscription(s), as well as an indication of which is your default. I have multiple Azure subscriptions, so this is what I see:

Note that the Azure CLI isn’t an interactive environment. In other words, you need to prefix all your Azure CLI command calls with azure. We use azure account list to view our subscriptions, and azure account set to specify a default account. I’ll use my 150dollar account as my default subscription today:

Now about getting help. Run azure help with no arguments to see a command list. It’s so brief that I’ll reprint the output in full here:

So, if we need to see command help for website-related tasks, we’d type:

Don’t type help site if you’re in a PowerShell session or you’ll run Get-Help to find commands that include “site” in their names! Remember—all Azure CLI calls need to start with “azure” and a space.

We can continue drilling down with the azure help command. For instance, to learn how to add a new database connection string programmatically to one of your sites, run this:

And so on. Pretty straightforward. When you’re ready to end your Azure CLI session, don’t forget to gracefully connect by running azure logout.

Managing Azure resources with the CLI ^

Azure CLI defaults to using Azure service management, but you can be sure of this by running azure config mode asm. By contrast, you run azure config mode arm if you want to use Resource Manager.

Today I’d like to focus on Azure Web Apps (formerly known as “Azure Websites”). We’ll start by listing my sites in the current subscription. And, yes, I’m aware that the following screenshot was taken from a Windows box. 😉

Listing Azure Web apps from the Azure CLI

Listing Azure web apps from the Azure CLI

By the way, I created the above DEV and PROD deployment slots like this:

We can easily swap our web app between deployment slots like so. The default slot is always named “production,” and here I’m swapping the 4sysops web app into the DEV slot. Under the covers, Azure actually duplicates the web app so they exist in both slots under different URLs:

Next steps ^

What do you think of the Azure CLI? Do you envision yourself using it from your Mac or Linux computer? I’ll leave you with some additional help resources to get you past your Azure CLI learning curve as quickly as possible:

Join the 4sysops PowerShell group!

0
Share
0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2019

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account