Your Azure Lab Toolkit: Azure CLI, PowerShell, Cloud Shell
-
Phase 0: Before you start
-
Phase 1: The foundation
-
Phase 2: Day-to-day operations
-
Phase 3: Enterprise architecture
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
Before you run any command, double-check it
Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.
A tidy Azure CLI setup on your laptop will save you hours over the rest of the course. The portal’s fine for looking around, but when you need to check twenty VMs or rebuild a lab in two minutes, you want commands.
Here you’ll install the Azure CLI, the Az PowerShell module and the Bicep tools, sign in with MFA and set a few defaults. Then you’ll create your first tagged resource group, find it with a query and delete it again.
Last of all you save a small script that lists everything this course has created in your subscription. Every lab from here on ends by running it, so nothing gets left running by accident.
| Time | You need | Cost | By the end you can |
|---|---|---|---|
| About 45 minutes | Windows 10 or 11, the Azure account from Lesson 2, admin rights to install apps | Nothing (a resource group is free) | Run az and Az PowerShell commands against your subscription, use tags and queries, and clean up with one script |
What it is, in one line
The Azure CLI (az) and Az PowerShell can do anything the portal does, but as commands you can repeat, check and share with others.
In Simple Words
Ordering food by phone instead of walking to the counter
Using the Azure portal is like walking up to a restaurant counter and pointing at pictures on the menu, which is easy enough until you need the same order for twenty people.
The Azure CLI is more like ringing the restaurant with a written list: “twenty plates, no onions, deliver at one”. You say it once and clearly, and next week you can read out the same list again.
Either way the order goes to the same kitchen and you get the same food. The phoned-in list is quicker and harder to get wrong.
Engineer's View
Three tools, one front door
- Azure CLI (
az): a cross-platform command-line tool written in Python. It returns JSON by default, and every command takes--query(JMESPath) and--output(json,table,tsv,yaml). Most labs in this course use it. - Az PowerShell module: cmdlets like
Get-AzVMandNew-AzResourceGroupthat give you back real PowerShell objects, which is handy if you already write PowerShell scripts. You can install just the parts you need, such asAz.AccountsandAz.Resources. - Bicep: a language for describing resources in files. The Azure CLI will install the Bicep tools for you with
az bicep install, and you’ll start using it in Lesson 41. - Cloud Shell: a shell in the portal, in your browser, with everything above already installed and signed in as you. It’s what you fall back on when your laptop is locked down.
Every one of them calls Azure Resource Manager at management.azure.com, the same as the portal. On Windows the CLI signs you in through the Windows sign-in broker (WAM) by default and then shows a list of your subscriptions to pick from. Since MFA is mandatory for create, update and delete actions from these tools, your token has to include MFA, and it will when you sign in interactively.
The CLI keeps its settings in %USERPROFILE%\.azure. Defaults like the location sit in the config file there, and the CLI mentions each one in its help text, so you can always tell where a value came from.
How it works, step by step
Here’s what happens when you run a single command such as az group create:
- The CLI reads your saved sign-in token and your default subscription.
- It adds any defaults you’ve set, like
location=centralindia. - It turns your arguments into a REST request, for example a
PUTto/subscriptions/<id>/resourcegroups/rg-saat-l03. - Azure Resource Manager checks RBAC and Azure Policy and then creates the group.
- The reply comes back as JSON, which
--queryfilters and--outputformats for you.
Put --debug on any command and you’ll see each of those steps, including the exact URL. When an error makes no sense, that’s the quickest way to work out what’s going on.
And here’s the habit that keeps your bill at zero. Everything this course creates gets two tags, course=saatvedha-azure and lesson=NN. A tag is a name and a value stuck on a resource, like a label on a box, and with those tags in place one query finds whatever you forgot to delete.
Hands-on lab: install, sign in, tag and clean up
You’ll install the tools, sign in, set defaults, create a tagged resource group, find it in two ways and then delete it. Run everything in Windows PowerShell unless a step tells you otherwise.
1Install the Azure CLI
Run this:
winget install --exact --id Microsoft.AzureCLIOnce it’s done, close PowerShell and open a fresh window. The installer adds az to your PATH, but windows that were already open won’t pick up the change.
In the new window, run this:
Set-Location C:\azure-lab
az versionYou should see something like this:
{
"azure-cli": "2.91.0",
"azure-cli-core": "2.91.0",
"azure-cli-telemetry": "1.1.0",
"extensions": {}
}2Sign in
Run this:
az loginA Windows sign-in window pops up. Pick the account from Lesson 2 and approve the MFA prompt, and back in PowerShell the CLI lists your subscriptions and asks you to choose one.
Press Enter to keep the one with the * next to it.
Then run this:
az account show --query "{subscription:name, user:user.name, tenant:tenantId}" -o tableYou should see something like this:
Subscription User Tenant
-------------------- --------------------- ------------------------------------
Azure subscription 1 priya.k@outlook.com 9a8b7c6d-1e2f-4a3b-8c9d-0e1f2a3b4c5d3Set your defaults
Run this:
az configure --defaults location=centralindia
az configure --list-defaults -o tableYou should see something like this:
Name Source Value
-------- ---------------------------------- ------------
location C:\Users\priya\.azure\config centralindiaFrom now on, any command that needs a location uses Central India unless you say otherwise. We don’t set a default resource group, because each lab has its own, and a forgotten default group is one of the classic ways to create things in the wrong place.
4Create a tagged resource group
A resource group is a folder for related resources, and deleting the folder deletes everything in it, which makes cleanup easy.
Run this:
az group create --name rg-saat-l03 --tags course=saatvedha-azure lesson=03 owner="Priya K" -o tableYou should see something like this:
Location Name
------------ -----------
centralindia rg-saat-l03Check the tags:
az group show --name rg-saat-l03 --query tagsYou should see something like this:
{
"course": "saatvedha-azure",
"lesson": "03",
"owner": "Priya K"
}5Find it with a query
Run this:
az group list --tag course=saatvedha-azure --query "[].{name:name, lesson:tags.lesson, location:location}" -o tableYou should see something like this:
Name Lesson Location
----------- -------- ------------
rg-saat-l03 03 centralindia--tag asks Azure to do the filtering on its side, and --query then keeps only the fields you want. You’ll use this pattern in nearly every lab.
6Do the same with Az PowerShell
Run this (the first time, it takes a few minutes):
Install-Module Az.Accounts, Az.Resources -Scope CurrentUser -Repository PSGallery -Force
Connect-AzAccount
Get-AzResourceGroup -Tag @{ course = 'saatvedha-azure' } | Select-Object ResourceGroupName, LocationIf PowerShell asks whether to install the NuGet provider, answer Y. Connect-AzAccount opens the same sign-in window and may then ask you to pick a subscription.
At the end you should see something like this:
ResourceGroupName Location
----------------- --------
rg-saat-l03 centralindiaIt’s the same group and the same answer from a different tool. The CLI hands you text and JSON, while Az PowerShell hands you objects you can pipe into other cmdlets.
7Add VS Code and the Bicep tools
Run this:
winget install --exact --id Microsoft.VisualStudioCode
az bicep install
az bicep versionYou should see something like this:
Bicep CLI version 0.48.1 (cec7951cf6)Open VS Code once, go to Extensions and install Bicep (by Microsoft). You won’t need it until Lesson 41, but installing it now saves time later.
8Save the cleanup checker you’ll use in every lab
Paste this whole block:
@'
param([string]$Lesson)
$groups = az group list --tag course=saatvedha-azure --query "[].{name:name, lesson:tags.lesson, location:location}" -o json | ConvertFrom-Json
$items = az resource list --tag course=saatvedha-azure --query "[].{name:name, type:type, group:resourceGroup, lesson:tags.lesson}" -o json | ConvertFrom-Json
if ($Lesson) {
$groups = $groups | Where-Object lesson -eq $Lesson
$items = $items | Where-Object lesson -eq $Lesson
}
if (-not $groups -and -not $items) { 'Nothing tagged course=saatvedha-azure is left.'; return }
if ($groups) { 'Resource groups:'; $groups | Format-Table -AutoSize | Out-String -Width 200 }
if ($items) { 'Resources:'; $items | Format-Table -AutoSize | Out-String -Width 200 }
'@ | Set-Content C:\azure-lab\Find-LabResources.ps1
C:\azure-lab\Find-LabResources.ps1You should see something like this:
Resource groups:
name lesson location
---- ------ --------
rg-saat-l03 03 centralindiaThe group appears, with no resources because it’s empty. If Windows says scripts are disabled, run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once and try again.

9Clean up
Run this:
az group delete --name rg-saat-l03 --yes
C:\azure-lab\Find-LabResources.ps1You should see this:
Nothing tagged course=saatvedha-azure is left.✅ Checkpoint: az version and Get-AzResourceGroup both work, your default location is centralindia, and Find-LabResources.ps1 says nothing is left.
Break It, Then Fix It
You’ll hit these two problems on nearly every new laptop or script. The first stops you dead, and the second slips through quietly and messes up your tags.
1Break it: run az in an old window
Open a PowerShell window before you install a tool, install it from a different window and then go back to the first one. Or just run this in a window that was already open during step 1:
az versionYou’ll get this error:
az : The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ az version
+ ~~
+ CategoryInfo : ObjectNotFound: (az:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundExceptionThe tool is installed, but this window still has the old PATH, because each process copies the PATH when it starts.
To fix it, close the window and open a new one. To check where az lives, run:
Get-Command az | Select-Object SourceYou should see something like this:
Source
------
C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin\az.cmd2Break it: a tag value with a space and no quotes
Run this:
az group create --name rg-saat-l03 --tags course=saatvedha-azure lesson=03 owner=Priya K -o none
az group show --name rg-saat-l03 --query tagsYou should see something like this:
{
"K": "",
"course": "saatvedha-azure",
"lesson": "03",
"owner": "Priya"
}There’s no error at all. --tags takes a space-separated list, so K turned into a tag of its own with an empty value, and the owner is now only “Priya”. Any report that groups costs by owner will be wrong from here on.
To fix it, remove the stray tag and set the owner in quotes:
az group update --name rg-saat-l03 --remove tags.K --set tags.owner="Priya K" -o none
az group show --name rg-saat-l03 --query tagsYou should see something like this:
{
"course": "saatvedha-azure",
"lesson": "03",
"owner": "Priya K"
}Then clean up again:
az group delete --name rg-saat-l03 --yes
C:\azure-lab\Find-LabResources.ps1
✅ Checkpoint: You can explain both errors, the tags are fixed and the checker reports nothing left.
This happened at work
The script that ran in the wrong subscription
The IT team at a hospital group had a nightly script that deleted test resource groups older than seven days. It ran with az on an admin’s jump server and used whichever subscription happened to be the default.
One afternoon the admin used that same server to check something in production, ran az account set to switch to the production subscription and forgot to switch back. That night the cleanup script ran against production and deleted three resource groups whose names began with “test-“, and one of them held the integration server for the lab results system.
Lab reports stopped reaching the doctors until a restore finished the following morning.
What they changed: the script now sets the subscription by ID on its first line and refuses to run if the subscription name contains “prod”. Deletes are driven by a tag (autodelete=true) instead of a name pattern, and the script runs as a managed identity with Contributor only on the test subscription, so even a mistake can’t reach production.
Common mistakes and troubleshooting
| Mistake | What you see | What to do |
|---|---|---|
| Running az in a window opened before installing | The term az is not recognized | Open a new window, and check with Get-Command az. |
| Tag values with spaces and no quotes | Extra tags with empty values | Put the whole value in quotes, owner=”Priya K”, and read the tags back after you create them. |
| A default resource group you forgot about | Resources appear in an old group | Don’t set a default group, or check it with az configure --list-defaults. |
| Bicep not installed | Bicep CLI not found. Install it now by running “az bicep install”. | Run az bicep install once. |
| Two tools signed in to different subscriptions | CLI and PowerShell show different results | Run az account show and Get-AzContext before you change anything. |
| Scripts blocked by policy | running scripts is disabled on this system | Set-ExecutionPolicy -Scope CurrentUser RemoteSigned. |
Interview questions
Click a question to open it. Each one is phrased the way an interviewer would ask it, and underneath you’ll find why they ask it and one way to answer in your own words.
Fresher level
1. What’s the difference between the Azure CLI and Azure PowerShell?
Why they ask this: They want to know you can use both and choose sensibly between them.
How you might answer: They both talk to Azure Resource Manager and can do the same things. The CLI is a command-line tool that returns JSON, which suits quick checks and bash or PowerShell scripts, while the Az module returns PowerShell objects that slot straight into PowerShell pipelines.
For most everyday checks I reach for the CLI, and I switch to Az PowerShell when I’m already writing a PowerShell script.
2. How do you check which subscription you’re working in before running a command?
Why they ask this: Wrong-subscription mistakes happen a lot and can be expensive, so they want to hear a safe habit.
How you might answer: I run az account show, or Get-AzContext in PowerShell. If I’m about to change something, I set the subscription explicitly by its ID first.
3. What is a resource group, in simple words?
Why they ask this: It’s a quick check on a basic concept.
How you might answer: It’s a folder for resources that live and die together, like the VM, disk, network card and IP of one app. At that level you can give access, apply tags and policies, see costs and delete the whole lot in one go.
2–5 years experience
4. A command works in Cloud Shell but fails on your laptop. How would you find out why?
Why they ask this: They want you to compare things methodically instead of guessing.
How you might answer: I’d compare the account and subscription on both sides with az account show, then the CLI versions with az version and any defaults with az configure --list-defaults. After that I’d run the failing command with --debug to see the exact request and response.
Usually it turns out to be a different subscription, an old CLI version or a proxy on the company network.
5. How do you get just the names and IPs of all VMs from the CLI, in a table?
Why they ask this: They’re checking you know --query and the output formats, since you’ll use them every day.
How you might answer: I’d run az vm list-ip-addresses with a JMESPath query, something like --query "[].{vm:virtualMachine.name, ip:virtualMachine.network.privateIpAddresses[0]}" -o table. JMESPath lets me pick fields and rename them, and -o table lays them out.
6. Why do you tag resources, and what tags would you start with?
Why they ask this: They want to hear how you tag in practice, not the theory.
How you might answer: Tags let me find, report on and clean up resources by owner, app and environment, and they show up in cost reports too. I’d begin with owner, app, environment and cost centre, and make them mandatory on new resources with Azure Policy.
In my lab everything gets course and lesson tags, so a single query shows whatever I forgot to delete.
Senior level
7. How would you stop people from running cleanup scripts against the wrong subscription?
Why they ask this: They want real controls, and “be careful” doesn’t count.
How you might answer: I’d have scripts set the subscription by ID and check its name or a tag before they do anything destructive. The script should run as a managed identity or service principal that only has rights where it’s meant to work, so a mistake can’t reach production.
Deletes should be based on tags like an expiry date rather than name patterns, and logged somewhere the team can review.
8. Your team mixes portal clicks, CLI scripts and Bicep. How would you bring some order?
Why they ask this: They’re checking whether you can move a team towards repeatable work without getting in their way.
How you might answer: I’d keep the portal for looking around and for emergencies, and move anything we build more than once into Bicep in a Git repo with pull requests. Small checks and reports can stay as CLI scripts in the same repo.
On top of that I’d add Azure Policy for required tags and allowed regions, so changes made in the portal follow the same rules.
9. What would you check when a new engineer’s CLI gets AuthorizationFailed but the portal works?
Why they ask this: They want to see you understand tenants, subscriptions and how tokens differ.
How you might answer: I’d first check the CLI is signed in to the same tenant and subscription as the portal. Then I’d ask whether the role was granted recently, because a token issued before the change won’t carry it, and a fresh az login often sorts that out.
If it still fails, I’d read the error, which names the action and the scope, and compare that with the role assignment.
Quick quiz
Q1. After installing the Azure CLI, an old PowerShell window says az is not recognized. Why?
- The install failed
- The window still has the old PATH
- You need to sign in first
- The CLI only works in Cloud Shell
Show answer
B — Each process reads PATH when it starts. Open a new window.
Q2. What does --query do?
- Filters the JSON reply with a JMESPath expression
- Sends a search to Bing
- Runs a KQL query
- Makes the command faster on the server
Show answer
A — The --query option runs a JMESPath expression on the reply, on your machine.
Q3. You run --tags owner=Priya K without quotes. What happens?
- An error
- owner is “Priya K”
- owner is “Priya” and a tag K with an empty value is added
- The tag is ignored
Show answer
C — Tags are separated by spaces, so K becomes its own tag.
Q4. Where does az configure --defaults save the location?
- In Azure Resource Manager
- In the config file in your .azure folder
- In the registry only
- In Cloud Shell
Show answer
B — Defaults are saved locally in %USERPROFILE%\.azure\config.
Q5. Why does every course resource get course and lesson tags?
- Tags make resources cheaper
- So one query finds everything left to delete
- Azure requires tags
- To make the portal faster
Show answer
B — Tags let Find-LabResources.ps1 list anything you forgot to clean up.
Quick recap
Your laptop now has the same tools Azure admins use every day, along with a habit that keeps your bill at zero.
- The Azure CLI, Az PowerShell and Bicep all go through Azure Resource Manager, the same as the portal.
- After installing a tool, open a new window, because old windows keep the old PATH.
- Set a default location, but not a default resource group.
- Put tag values with spaces in quotes, and read the tags back afterwards.
- Finish every lab with C:\azure-lab\Find-LabResources.ps1.
Next lesson
Lesson 4: Azure regions, availability zones and billing → You’ll list the regions and zones open to you, see which services each one offers, and learn how tags and Cost analysis show what you’re spending.
Further reading: Azure CLI setup
If you want to go further with Azure CLI setup, Microsoft’s install guide is Install the Azure CLI on Windows, and JMESPath queries are covered in How to query Azure CLI command output. The full plan for this course is on the Azure Cloud Administration course page.
