Azure PowerShell
Overview
-
Azure PowerShell is a module for Windows PowerShell or PowerShell Core.
-
Allows you to connect to Azure subscriptions and manage resources.
-
Example: Creating a VM:
New-AzVm -ResourceGroupName "CrmTestingResourceGroup" -Name "CrmUnitTests" -Image "UbuntuLTS"
-
Can run in:
-
Interactive mode: One command at a time.
-
Scripting mode: Execute scripts containing multiple commands.
-
-
Az Module:
-
Replacement for the older
AzureRMmodule. -
Provides
-Azcmdlets, backward compatible with-AzureRM. -
Open-source: Azure PowerShell GitHub
-
Covers: Resource Groups, Storage, VMs, Azure AD, Containers, Machine Learning, etc.
-
PowerShell Cmdlets & Modules
-
Cmdlet: Single-purpose PowerShell command (
verb-nounformat, e.g.,Get-Process). -
Common verbs:
get(retrieve),set(update),format(format output),out(redirect output). -
Get-Helpshows detailed cmdlet info:
Get-Help Get-ChildItem -Detailed
-
Modules are collections of cmdlets:
Get-Module
Demonstration: Install Az Module
-
Open PowerShell as administrator.
-
Set execution policy if needed:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
-
Install the module:
Install-Module -Name Az -AllowClobber
-
Install NuGet provider if prompted.
-
Trust the repository when prompted.
Connect to Azure & Manage Resources
# Login
Connect-AzAccount# Verify subscriptionGet-AzSubscription
# Create a resource group
New-AzResourceGroup -Name <name> -Location <location>
# Verify resource group
Get-AzResourceGroup
# Remove resource group
Remove-AzResourceGroup -Name <name>
Azure CLI
Overview
-
Cross-platform command-line tool (Linux, macOS, Windows).
-
Can run interactively or via scripts.
-
Example: Restart a VM:
az vm restart -g MyResourceGroup -n MyVm
-
Commands are structured in groups and subgroups (e.g.,
az storage blob).
Finding Commands
# Search for commands
az find -q blob# Get detailed helpaz storage blob —help
Demonstration: Install & Use Azure CLI
Install on Windows:
-
Go to Install Azure CLI Windows
-
Run installer, accept license, click Install.
Verify Installation:
az --version
Login:
az login
-
Browser opens for authentication, or use
https://aka.ms/devicelogin.
Create a Resource Group:
az group create --name <name> --location <location>
Verify Resource Group:
az group list
az group list --output table
az group list --query "[?name == '<rg name>']"
Key Differences
| Feature | Azure PowerShell | Azure CLI |
|---|---|---|
| Platform | PowerShell (Windows/macOS/Linux) | Shell/Command line (Windows/Linux/macOS) |
| Syntax | Verb-Noun (Get-AzVM) |
az <group> <command> |
| Scripts | PowerShell scripts | Shell scripts (Bash, CMD, PowerShell) |
| Use case | Deeper integration with PowerShell, automation | Cross-platform, scripting friendly, simple syntax |