0
0
Azurecloud~5 mins

Azure PowerShell module basics - Commands & Configuration

Choose your learning style9 modes available
Introduction
Managing cloud resources can be complex. Azure PowerShell modules let you control Azure services using simple commands in a PowerShell window. This helps automate tasks and manage resources easily.
When you want to create or delete Azure virtual machines without using the web portal.
When you need to automate deployment of storage accounts or databases.
When you want to check the status of your Azure resources quickly from your computer.
When you want to script repetitive tasks like starting or stopping virtual machines.
When you prefer command-line tools over graphical interfaces for managing Azure.
Commands
This command installs the Azure PowerShell module named 'Az' for the current user. It allows overwriting any existing conflicting commands.
Terminal
Install-Module -Name Az -AllowClobber -Scope CurrentUser
Expected OutputExpected
Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y Installing package 'Az'...
-AllowClobber - Allows overwriting existing commands if there is a conflict.
-Scope CurrentUser - Installs the module only for the current user without needing admin rights.
This command opens a login window to sign in to your Azure account. It authenticates your PowerShell session to manage Azure resources.
Terminal
Connect-AzAccount
Expected OutputExpected
Account SubscriptionName TenantId Environment ------- ---------------- -------- ----------- your.email@example.com Your Subscription Name xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx AzureCloud
This command lists all Azure subscriptions linked to your account. It helps you see which subscriptions you can manage.
Terminal
Get-AzSubscription
Expected OutputExpected
Name Id State ---- -- ----- Your Subscription Name xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Enabled
This command sets the active subscription context to the one with the given ID. It ensures your commands affect the right subscription.
Terminal
Set-AzContext -SubscriptionId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Expected OutputExpected
Name Account SubscriptionId TenantId Environment ---- ------- -------------- -------- ----------- Your Subscription Name your.email@example.com xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx AzureCloud
-SubscriptionId - Specifies which subscription to use for subsequent commands.
This command lists all resource groups in the current subscription. Resource groups organize your Azure resources.
Terminal
Get-AzResourceGroup
Expected OutputExpected
ResourceGroupName Location ProvisioningState ----------------- -------- ----------------- myResourceGroup eastus Succeeded
Key Concept

If you remember nothing else, remember: Azure PowerShell modules let you control Azure resources easily from the command line after you install the module and sign in.

Common Mistakes
Trying to run Azure commands without installing the Az module first.
PowerShell does not recognize Azure commands without the module installed.
Run 'Install-Module -Name Az -AllowClobber -Scope CurrentUser' to install the module before using Azure commands.
Not signing in with Connect-AzAccount before running commands.
Commands fail because PowerShell is not authenticated to your Azure account.
Always run 'Connect-AzAccount' and complete login before managing resources.
Running commands in the wrong subscription context.
Commands affect the wrong subscription, causing confusion or errors.
Use 'Set-AzContext -SubscriptionId <id>' to select the correct subscription.
Summary
Install the Azure PowerShell module using Install-Module to get Azure commands.
Sign in to your Azure account with Connect-AzAccount to authenticate.
Check and set your subscription context with Get-AzSubscription and Set-AzContext.
List your resource groups with Get-AzResourceGroup to see your organized resources.