AZ-104 Phase 3 — Shell Reference
Sorted by frequency. The Azure CLI (az ...)
works identically in both — only the surrounding shell syntax differs.
$PSVersionTable — if it returns a version
table, you're in PowerShell. If you see an error, you're in Bash. Azure Cloud Shell defaults to Bash; local
Windows terminals usually default to PowerShell.
| Frequency | Concept | PowerShell | Bash |
|---|---|---|---|
| Variables & output — you'll see these in every script | |||
| Very high |
Variables
Assignment & use
|
$name = "east-us"
Always $ on both sides
|
name="east-us" → read as $name
No $ on left; $ only when reading
|
| Very high |
Print to screen
|
Write-Host "hello"
or just type the value
|
echo "hello" |
| Very high |
Capture output
Command → variable
|
$rg = az group list |
rg=$(az group list) |
| String building — constructing resource names & IDs | |||
| Very high |
Embed variable in string
|
"rg-$name"
Double quotes expand; single quotes are literal
|
"rg-$name" or "rg-${name}"
Same double/single rule
|
| Medium |
Multi-line command
|
` backtick at line end |
\ backslash at line end |
| Environment & shell identity | |||
| Very high |
Environment variables
|
$env:HOME / $env:PATH |
$HOME / $PATH |
| Very high |
Pipeline
Chain commands
|
cmd | Select-Object Name
Passes structured objects
|
cmd | grep "name"
Passes plain text
|
| Medium |
Which shell am I in?
|
$PSVersionTable |
echo $SHELL or ps -p $$ |
| Control flow — conditionals & loops | |||
| Medium |
If / else
|
if ($x -eq "val") { ... }
Operators: -eq -ne -gt -lt
|
if [ "$x" = "val" ]; then ... fi
Operators: = != -gt -lt
|
| Medium |
For loop
|
foreach ($i in $list) { ... } |
for i in "${list[@]}"; do ... done |
| Less common — recognise, don't memorise | |||
| Lower |
Functions
|
function Greet { param($n) "Hi $n" } |
greet() { echo "Hi $1"; } |
| Lower |
Error handling
|
try { ... } catch { ... } |
cmd || echo "failed" or set -e |
| Lower |
Here-string
Multi-line literal
|
@"...multi-line..."@ |
<<EOF ... EOF |
| Pattern | What to run | When to use it |
|---|---|---|
| Finding the right az command — drill-down with --help | ||
|
Step 1 — find the service group
|
az monitor --help
Lists all subgroups under az monitor
|
You know the service (monitor, network, keyvault) but not the subgroup. Read the list — log-analytics, diagnostic-settings, etc will appear. |
|
Step 2 — find the noun
|
az monitor log-analytics --help
Shows subgroups: workspace, cluster, etc
|
Drill into the subgroup. Each level narrows further until you reach commands (show, create, delete, list). |
|
Step 3 — find the flags
|
az monitor log-analytics workspace show --help
Shows all flags, required vs optional, and examples
|
The final --help shows every flag. Required flags are marked. Examples section at the bottom is the fastest path to correct syntax. |
| Finding JSON shapes — use show before create | ||
|
show an existing resource
Get the exact JSON shape Azure expects
|
az monitor diagnostic-settings show \
Returns the full JSON of an existing setting
|
When --help says "JSON encoded list" but gives no example: run show on an existing resource first. Copy that JSON shape into your create command. This works for --logs, --metrics, --rules, and any other complex JSON flag. |
|
list available categories
Find valid values for --logs categories
|
az monitor diagnostic-settings categories list \
|
Every resource type exposes different log categories (AuditEvent, StorageRead, AppServiceHTTPLogs, etc). This command returns exactly what is valid for that specific resource — no guessing. |
| Flag shorthand — both forms are always valid | ||
|
Common shorthand flags
|
-g = --resource-group-n = --name-l = --location-o = --output
|
Azure CLI defines shorthand aliases for the most common flags. Both forms work identically — -g rg-name and --resource-group rg-name produce the same result. Use shorthand in scripts you run often, full form when readability matters. |
Commands pass structured objects — like handing someone a filled-out form with labelled fields.
You can ask for a specific field by name: | Select-Object Name
Commands pass plain text — like handing someone a sticky note. You parse it yourself.
You use text tools to find what you need: | grep "name"