Do the same jobs in Azure PowerShell
In this task you'll manage Azure with Azure PowerShell.
Azure PowerShell is the other command-line way to manage Azure, alongside the Azure CLI. Its commands follow PowerShell's Verb-Noun style, such as Get-AzResourceGroup, and they return objects you can filter and sort.
Both tools do the same jobs, so use whichever your team knows. People who already manage Windows servers often prefer PowerShell. Cloud Shell has both ready to use.
Example. Larkfield Group's Windows administrators already script their servers in PowerShell, so they use the Az module for Azure too, and keep one script that lists every VM without an owner tag.
Before you start
You need: Reader to look; Contributor to create. Time: 10 minutes.
Where to look
- Cloud Shell
- Switch to PowerShell
Steps
- Open Cloud Shell, select Switch to PowerShell in its toolbar and Confirm. You're signed in already.
- List your resource groups:Type
Get-AzResourceGroup | Select-Object ResourceGroupName, Location - Create a practice group:Type
New-AzResourceGroup -Name rg-ps-practice -Location uksouth -Tag @{env='practice'} - Find every resource group with that tag:Type
Get-AzResourceGroup -Tag @{env='practice'} - Look up the help for any command:Type
Get-Help New-AzResourceGroup -Examples - Delete the group:Type
Remove-AzResourceGroup -Name rg-ps-practice -Force. Then switch back to Bash if you prefer it.
Commands
# The same jobs in the Azure CLI, for comparison
az group list --query "[].{name:name, location:location}" --output table
az group create --name rg-ps-practice --location uksouth --tags env=practice
az group list --tag env=practice --output table
az group delete --name rg-ps-practice --yes
Watch out for
- Cost
- Running commands is free. An empty resource group costs nothing.
- Security
-Forceskips the "are you sure?" question, so double-check names before using it. Never save passwords in scripts.- Common mistakes
- Mixing Azure CLI syntax (
az group list) with PowerShell syntax. Forgetting that tag values are written as@{name='value'}in PowerShell.
Clean up
- Resource groups
- rg-ps-practice
- Delete resource group
Make sure rg-ps-practice is deleted, with Remove-AzResourceGroup or in the portal.
Words to know
- Az module
- The PowerShell module for Azure. Its commands all start with a verb and Az, such as Get-AzVM.
- Cmdlet
- A PowerShell command, named Verb-Noun.
- Pipeline
- The | symbol, which passes one command's results to the next.
Tick off each step and track your progress in the guide.
Open this task in Azure Portal, Hands On