Using Azure CLI and Azure PowerShell
AZ-104 notes: Using Azure CLI and Azure PowerShell. Covers key concepts for the Azure Administrator Associate exam.
- Structured Summary + Deep Understanding
Primary tools:
- Azure CLI
- Azure PowerShell
Official documentation:
Azure CLI:
Azure PowerShell:
1️⃣ What is Azure CLI?
Azure CLI is:
✔ A cross-platform command-line tool ✔ Used to manage Azure resources ✔ Bash-style syntax ✔ Script-friendly ✔ Available in:
- Cloud Shell
- Windows
- macOS
- Linux
Core command structure:
- az
<service><resource><action>
Example:
- az vm create
Azure CLI interacts with:
- → Azure Resource Manager (control plane)
2️⃣ What is Azure PowerShell?
Azure PowerShell is:
- ✔ A collection of PowerShell cmdlets (Az module) ✔ Object-oriented ✔ Built on .NET ✔ Used to manage Azure resources
Cmdlet naming pattern:
- Verb-AzNoun
Example:
- New-AzVM
Like CLI, it interacts with:
- → Azure Resource Manager (control plane)
3️⃣ CLI vs PowerShell – Core Differences
Both are equally capable.
Choice = Preference + Team ecosystem.
4️⃣ Demonstration Breakdown
Example scenario:
- Create a Virtual Network.
Resource example:
- Azure Virtual Network
5️⃣ Azure CLI Workflow Explained
🔹 Step 1: List Resource Groups
az group list
Default output: JSON array.
🔹 Step 2: Filter Output Using --query
- Azure CLI supports JMESPath queries.
Example:
- az group list --query "[].name"
- This extracts only the name field.
🔹 Step 3: Change Output Format
- Default = JSON Better for scripting = TSV (tab-separated value)
- az group list --query "[].name" --output tsv
- Why?
- Removes brackets and quotes.
🔹 Step 4: Save to Variable
- rgcli=$(az group list --query "[].name" --output tsv)
Use variable later:
- echo $rgcli
🔹 Step 5: Create Virtual Network
- az network vnet create \
- --name VNetCLI \
- --resource-group $rgcli \
- --address-prefix 10.0.0.0/16
Command pattern:
- az network vnet create
- ProvisioningState: Succeeded
6️⃣ Azure PowerShell Workflow Explained
🔹 Step 1: Get Resource Group
Get-AzResourceGroup
Returns PowerShell objects (not JSON).
🔹 Step 2: Save to Variable
$rgps = Get-AzResourceGroup
PowerShell stores full object.
🔹 Step 3: Access Object Properties
- $rgps.ResourceGroupName
- $rgps.Location
Object model advantage:
- You can drill into properties directly.
🔹 Step 4: Create Virtual Network
- New-AzVirtualNetwork `
- -Name VNetPS `
- -ResourceGroupName $rgps.ResourceGroupName `
- -Location $rgps.Location `
- -AddressPrefix 10.1.0.0/16
- ProvisioningState: Succeeded
7️⃣ Key Architectural Concept
Both CLI and PowerShell:
- User Command → REST API call → Azure Resource Manager → Resource Provider (Microsoft.Network) → Resource Created
- They are simply different interfaces to ARM.
8️⃣ Object-Oriented Advantage (PowerShell)
- PowerShell returns structured objects.
Example:
- $vm = Get-AzVM
- $vm.HardwareProfile.VmSize
You can chain and pipe objects:
- Get-AzVM | Where-Object {$_.Location -eq "eastus"}
- This makes PowerShell powerful for complex logic.
9️⃣ JSON Advantage (CLI)
- CLI returns JSON by default.
Best for:
- DevOps pipelines
- Automation systems
Integration with tools like:
- jq
- Terraform
- Ansible
Example:
- az vm list --output table
Supports formats:
- json
- jsonc
- table
- tsv
- yaml
🔟 When to Use Each
🔹 Use Azure CLI When:
✔ Working in Linux ✔ Writing CI/CD pipelines ✔ Using Bash ✔ Automating DevOps workflows
🔹 Use Azure PowerShell When:
✔ Using Windows ecosystem ✔ Need object manipulation ✔ Writing complex automation ✔ Managing enterprise scripts
1️⃣1️⃣ Cloud Shell Integration
In:
- Azure Cloud Shell
You can:
- Run Azure CLI (Bash)
- Run Azure PowerShell (PowerShell)
- Switching shells restarts session.
- Cloud Shell is pre-authenticated.
1️⃣2️⃣ Authentication Model
Both tools authenticate via:
- Microsoft Entra ID
Process:
- Login → Token issued → Token passed to ARM → RBAC enforced → Action executed
1️⃣3️⃣ Common Exam Pitfalls
🚩 CLI and PowerShell manage data plane directly → False 🚩 PowerShell returns JSON → False 🚩 CLI cannot be scripted → False 🚩 Both use ARM → True 🚩 PowerShell is better than CLI → False (preference-based)
1️⃣4️⃣ Advanced Automation Insight
For production automation:
- ✔ Use variables ✔ Use output formatting ✔ Validate provisioning state ✔ Handle errors ✔ Use idempotent scripts
Example:
Check before creating:
CLI:
- az network vnet show --name VNetCLI
PowerShell:
- Get-AzVirtualNetwork -Name VNetPS
1️⃣5️⃣ Mental Model
Portal = GUI CLI = Scriptable Bash interface PowerShell = Scriptable object-oriented interface
All communicate with ARM.
1️⃣6️⃣ Final Takeaways
- ✔ Azure CLI = Bash-style, JSON-based ✔ Azure PowerShell = Object-oriented cmdlets ✔ Both automate Azure ✔ Both integrate with Cloud Shell ✔ Both use ARM ✔ Preference depends on ecosystem
These tools are foundational for:
- AZ-104
- AZ-204
- DevOps roles
- Automation engineering
- Enterprise scripting
If you'd like next:
- 🧠 30 CLI vs PowerShell exam questions
- 🏗 Advanced scripting patterns
- 🚀 DevOps pipeline examples
- 🔐 Secure automation best practices
- 📊 ARM + CLI + PowerShell interaction diagram
- Tell me your goal.
