Skip to content

Azure 101⚓︎

Difficulty:
Direct link: Objective5.zip

image

Objective⚓︎

Request

Help Sparkle Redberry with some Azure command line skills. Find the elf and the terminal on Christmas Island.

Sparkle Redberry

Hey, Sparkle Redberry here! So, I've been trying to learn about Azure and the Azure CLI and it's driving me nuts.

Alabaster Snowball decided to use Azure to host some of his fancy new IT stuff on Geese Islands, and now us elves have to learn it too.

Anyway, I know it's important and everyone says it's not as difficult as it seems, but honestly it still feels like quite a challenge for me.

Alabaster sent us this Azure CLI reference as well. It's super handy, he said. Honestly, it just confuses me even more.

If you can spare a moment, would you mind giving me a hand with this terminal? I'd be really grateful! Pretty please, with holly leaves on top!

Hints⚓︎

Azure CLI Reference

The Azure CLI tools come with a builtin help system, but Microsoft also provides this handy cheatsheet.

Solution⚓︎

Azure CLI⚓︎

az help | less
azhelp
az account show
account
az resource show
resource

Chacho

How do i get a list of resource groups using azure cli?

ChatGPT

To get a list of resource groups using Azure CLI, you need to use the az group list command. This command retrieves all the resource groups in your Azure subscription. Here's how you can use it:

Open Command Line Interface: First, open your command line interface (CLI).

Login to Azure: If you haven't already logged in to your Azure account, use the command:

az login
This will open a browser window where you can enter your Azure credentials.

List Resource Groups: Once logged in, use the following command to list all resource groups:

az group list --output table
The --output table argument formats the list in a table for better readability. You can also use other output formats like json, yaml, jsonc, etc.

Filtering: If you want to filter the list, you can add query arguments. For example, to list resource groups in a specific location, you can use:

az group list --query "[?location=='eastus']" --output table
This will provide you with a list of all resource groups in your Azure subscription, along with details like the resource group name, location, and provisioning state. Make sure you have the necessary permissions and that Azure CLI is installed and up-to-date on your system.

az group list --output table

grouplist

Chacho

How do I get a list of function apps for this resource group: northpole-rg1

ChatGPT

To get a list of function apps within a specific resource group, such as "northpole-rg1", using Azure CLI, you would typically use the az functionapp list command with a query to filter by the resource group. Here's how you can do it:

Open Command Line Interface: First, ensure your command line interface (CLI) is open.

Login to Azure: If you're not logged in, use the command:

az login
This will prompt you to log in via a browser window.

List Function Apps in the Resource Group: To list all function apps in the "northpole-rg1" resource group, use the following command:

az functionapp list --resource-group northpole-rg1 --output table
The --output table argument is optional but provides a formatted table view which is often more readable. You can choose other formats like json, yaml, etc., depending on your preference.

Filtering: If you need more specific information or filtering, you can use the --query parameter to customize the output further.

Remember, you need to have Azure CLI installed on your system and the necessary permissions to view these resources in your Azure subscription.

az functionapp list --resource-group northpole-rg1 --output table
functionapp

Chacho

What command do I use to list the VMs in a resource group? (I am already logged in)

ChatGPT

To list the virtual machines (VMs) in a specific resource group using Azure CLI, and assuming you are already logged in, you can use the az vm list command with the appropriate parameters. Here's the command you would use:

az vm list --resource-group YOUR_RESOURCE_GROUP_NAME --show-details --output table
Replace YOUR_RESOURCE_GROUP_NAME with the name of your resource group. In this command:

--resource-group specifies the resource group. --show-details provides additional details about each VM. --output table formats the output as a table for better readability. You can also use other output formats like json, yaml, etc., depending on your needs. This will give you a list of all VMs in the specified resource group along with detailed information about each VM.

az vm list --resource-group northpole-rg2 --show-details --output table

Unauthorized

While northpole-rg1 indicates the user is not authorized, northpole-rg2 provides the vm information.

vm

Chacho

How do I use a run-command against vm NP-VM1 in resource group northpole-rg2 to get a directory listing?

ChatGPT

To execute a command on a virtual machine (VM) using Azure CLI's az vm run-command, you can use the run-command invoke subcommand. This allows you to run scripts or commands directly on a VM in Azure. To get a directory listing on a VM named "NP-VM1" in the resource group "northpole-rg2", you would typically use a command like this:

For a Linux VM:⚓︎

az vm run-command invoke --resource-group northpole-rg2 --name NP-VM1 --command-id RunShellScript --scripts "ls -l"

For a Windows VM:⚓︎

az vm run-command invoke --resource-group northpole-rg2 --name NP-VM1 --command-id RunPowerShellScript --scripts "Get-ChildItem"
In these commands:

--resource-group specifies the name of the resource group. --name is the name of the VM. --command-id is the type of command to run (RunShellScript for Linux VMs or RunPowerShellScript for Windows VMs). --scripts is followed by the actual command you want to run on the VM (ls -l for a directory listing in Linux or Get-ChildItem for Windows). Make sure you adjust the command according to the operating system of your VM. The output will display the result of the directory listing command executed on the VM.

az vm run-command invoke --resource-group northpole-rg2 --name NP-VM1 --command-id RunShellScript --scripts "ls -l"
Objective Answer

run-command

Response⚓︎

Sparkle Redberry

Wow, you did it!

It makes quite a bit more sense to me now. Thank you so much!

That Azure Function App URL you came across in the terminal looked interesting.

It might be part of that new project Alabaster has been working on with the help of ChatNPT.

Let me tell you, since he started using ChatNPT he's been introducing a lot of amazing innovation across the islands.

Knowing Alabaster, he'll be delighted to tell you all about it! I think I last saw him on Pixel island.

By the way, as part of the Azure documentation he sent the elves, Alabaster also noted that if Azure CLI tools aren't available in an Azure VM we should use the Azure REST API instead.

I'm not really sure what that means, but I guess I know what I'll be studying up on next.